I will be writing this guide as a part of my upcoming “Arch System Maintenance Guide”. When you are using Linux, you should always take regular backups. It is secure, it is stable and all that, but backup is very important to aid you in case you make a mess of your system. I will be writing the script to backup the entire system, excluding a few folders/files,etc. So here is the script.
mkdir ~/.rsync && cd ~/.rsync wget http://s2.sigmirror.com/files/53582_x8b8x/rsync.sh wget http://www.sigmirror.com/files/50262_e92yu/exclude wget http://www.sigmirror.com/files/50261_xjpd3/warn
Now, make sure you have rsync and zenity installed. If you are using Gnome, zenity should already be installed but just in-case, if you are using a Debian-based distro like ubuntu, or even Debian do:
sudo apt-get install zenity rsync
If you are using Xdialog instead, open the warn file and replace the zenity line with:
Xdialog --msgbox Plugin\ Your\ Backup\ Drive 10 50
Save it and exit. If for some reason cron fails to launch the Warning message box, put “DISPLAY=:0″ in front of zenity or Xdialog line.
Now, in my script I have started backup from root, excluding a few directories like /proc, /dev , and a few of my personal files. So you need to edit that file. Open the exclude file with a text editor [nano], and remove my folders [I kept them intentionally to make you do some work, lol ;-) ] and add whatever files or folders you would like to exclude from Backing up. We also exclude all .bak and .~ files from backups.
Edit the rsync.sh file to specify what drive path to use for backup. I use /media/backup in my External HDD. So replace that accordingly.
Now it’s time to edit your cron.
sudo nano /var/spool/cron/your-user-name-here 10 8 * * * ~/.rsync/warn 1> /dev/null sudo nano /var/spool/cron/root 15 8 * * * /home/username/.rsync/rsync.sh 1> /home/username/cronlog
Set the backup time according to your preference. The first field is minutes and the next one is hours. So cron warns me with a popup message box warning me to Plugin my External HDD for Backup and 5 minutes later my Backup starts. If you want to keep a weekly or monthly [not recommended!] backup instead, create your cron line easily using this.
After this save it and exit, check if the entry was created:
sudo crontab -l $USER
You may need to restart cron daemon:
sudo /etc/rc.d/crond restart
Or init.d, whatever your system uses. You can even reboot if you want to.
Also make sure all the scripts have execute permissions on them:
sudo chmod +x ~/.rsync/*