Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I write a script which creates incremental backups using rsync or what are the parameters to do the incremental backup?

Here's the scenario:

I have a samba file server and I need to backup to usb external drive any changes or additional files created on a specific samba folder. Location of files that I need backup (/opt/Resources and /opt/Resources Shared Folder 2) and the destination (/media/disk/Resources Files Backup).

I tried to create a file (zipfiletest) on /opt/Resources and manually run rsync to see if the file transfer to the usb external hard drive, it seems it works but I don't know how to do it automatically if ever there's a new file created or modified from the samba source.

[root@fileserver Resources]# rsync -azv /opt/Resources/zipfiletest /media/disk/Resources\ Files\ Backup01292013/Resources
sending incremental file list
zipfiletest/

sent 47 bytes  received 16 bytes  126.00 bytes/sec
total size is 0  speedup is 0.00
share|improve this question
add comment

migrated from stackoverflow.com Jan 31 '13 at 7:52

This question came from our site for professional and enthusiast programmers.

2 Answers

rsync can create hardlinks to files in another directory. So when you backup to directory containing current date in it's name, you can pass --link-dest argument pointing to previous backup. In result you will have two identical (if there was no change between backups) directories that take up space only for one.

Another solution is called rdiff-backup. It uses rsync protocol and handles incrementals for you. It uses some extra files to store diff to older versions (no hardlinks). I use it and it works nicely, but when comes to restoring old versions, it is slow.

share|improve this answer
add comment

Here's how I solved my own question.

From Samba File Server:

Source:

/opt/Resources
/opt/Resources Shared Folder 2

Destination:

/media/disk/Resources Files Backup/Resources
/media/disk/Resources Files Backup/Resources Shared Folder 2

Script:

backup.sh

rsync -azv /opt/{Resources,Resources\ Shared\ Folder\ 2/} /media/disk/Resources\ Files\ Backup/Resources/

Location of backup script:

/usr/local/bin

crontab run at midnight of every day

0 0 * * * /usr/local/bin/backup.sh
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.