[script] Easy Backup Solution using rsync
Originally Posted in my Blog.
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.
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:
Rsync is already present there for Slackers, check out zenity at Slackbuilds. Note: This will require a few Gnome dependencies, so you can use xdialog or a Qt equivalent tool.
If you are using Xdialog instead, open the warn file and replace the zenity line with:
Save it and exit.
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.
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:
You may need to restart cron daemon:
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:
Enjoy! :-)
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.
Code:
mkdir ~/.rsync && cd ~/.rsync wget http://www.sigmirror.com/files/50264_tbsix/rsync.sh wget http://www.sigmirror.com/files/50262_e92yu/exclude wget http://www.sigmirror.com/files/50261_xjpd3/warn
Code:
sudo apt-get install zenity rsync
If you are using Xdialog instead, open the warn file and replace the zenity line with:
Code:
Xdialog --msgbox Plugin\ Your\ Backup\ Drive 10 50
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.
Code:
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
After this save it and exit, check if the entry was created:
Code:
sudo crontab -l $USER
Code:
sudo /etc/rc.d/crond restart
Also make sure all the scripts have execute permissions on them:
Code:
sudo chmod +x ~/.rsync/*
Total Comments 0