Share your knowledge at the LQ Wiki.
Go Back > Blogs > ~sHyLoCk~
User Name


Rate this Entry

[script] Easy Backup Solution using rsync

Posted 01-03-2010 at 10:03 AM by ~sHyLoCk~
Updated 01-05-2010 at 10:14 PM by ~sHyLoCk~

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.

mkdir ~/.rsync && cd ~/.rsync
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
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:

 Xdialog --msgbox Plugin\ Your\ Backup\ Drive 10 50
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 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/ 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/*
Enjoy! :-)
Posted in Scripts
Views 2975 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 02:43 PM.

Main Menu

Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration