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

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

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

3 Answers 3

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

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

From http://rdiff-backup.nongnu.org/

A remote incremental backup of all your files could be as easy as "rdiff-backup / host.net::/target-dir"[disclaimer] What is it?

rdiff-backup backs up one directory to another, possibly over a network. The target directory ends up a copy of the source directory, but extra reverse diffs are stored in a special subdirectory of that target directory, so you can still recover files lost some time ago. The idea is to combine the best features of a mirror and an incremental backup. rdiff-backup also preserves subdirectories, hard links, dev files, permissions, uid/gid ownership, modification times, extended attributes, acls, and resource forks. Also, rdiff-backup can operate in a bandwidth efficient manner over a pipe, like rsync. Thus you can use rdiff-backup and ssh to securely back a hard drive up to a remote location, and only the differences will be transmitted. Finally, rdiff-backup is easy to use and settings have sensical defaults.

share|improve this answer

Your Answer

 
discard

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