LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Blogs > ~sHyLoCk~
User Name
Password

Notices


Rating: 2 votes, 5.00 average.

[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.

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
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:

Code:
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:

Code:
 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 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
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:

Code:
sudo crontab -l $USER
You may need to restart cron daemon:

Code:
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:

Code:
sudo chmod +x ~/.rsync/*
Enjoy! :-)
Posted in Scripts
Views 4706 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 10:09 PM.

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