I'm trying to learn how to use rsync. I want to create daily backs up of my production server.

Right now I run the command

rsync -azr /var/www/* www-data@backup.server.com:/var/www

Now let's say one day, I want to roll back the /var/www/ directory on my production server to last month's version. How do I tell rsync to retrieve version N?

On reading that rsync only copies differences between src and dest, I assumed rsync works like subversion where you commit changes to a destination, and keep track of every version, and with the option to checkout any version at anytime. Is that the way rsync works? It's like subversion but for an entire server? That would be great because then it means I don't have to do full ssh copies for my nightly backups.


rsync mirrors your current filestructure to the other side. It sends only the differences in the files, but does not keep revisions.


might be closer to what you want to do. For a less 'manual' method, http://rsnapshot.org/

| improve this answer | |

rsync is not a version control system. It operates on the bare filesystem objects and add, updates, and deletes them directly as necessary. Other tools may add some sort of versioning, but there is no way to rollback using bare rsync.

| improve this answer | |
  • .. except that rsync has a backup mode which can create symlinks to prior versions of a copy so that you can have directories containing "versions" of copies. – PP. Apr 19 '10 at 0:22
  • @PP but johnlai2004 isn't using it; he's totally confused. – Javier Apr 19 '10 at 2:19
  • @Javier well it doesn't help when Ignacio gives a confusing answer falsely saying there's no way to roll back. There is! – PP. Apr 19 '10 at 10:37
  • Ignacio is correct. Even --backup is not version control. It's still backups and you cannot simply revert to a given version automatically. – Magellan Nov 22 '14 at 15:35

You can, with a little glue from Bash in your script, do an incremental daily backup; I use a modified version of this script to backup my development server files: http://samba.anu.edu.au/rsync/examples.html

| improve this answer | |

I do a backup using the following options:

      -avP --stats --compress \
      --delete \
      -b --backup-dir ${DIRBACKUPBACKUP} \
      --bwlimit=20 \
      --include=/etc/ \
      --include=/etc/** \
      --include=/var/ \
      --include=/var/vmail/ \
      --include=/var/vmail/** \
      --exclude=* \

where ${DIRBACKUPBACKUP} is a unique directory name (I use the current date and time).

There's no automatic way to recover but I should be able to reconstruct what the directory looked like on any particular day using these options.

| improve this answer | |

If your goal is to be able to roll back the code to another time period, it would be wise to keep it in a subversion repo and use something like Capistrano to check it out for test/production.

With Capistrano my developers can email our QA group the tag and revision number of the PHP app they want to deploy for testing. QA can edit the Capistrano file to include that revision and tag, then run ENVIRONMENT=testing;cap deploy. Capistrano will log on to our Test servers and deploy that version of the code according to the recipe I wrote for them.

The move into production is the same process, but we set ENVIRONMENT=production

If you need to roll back to a previous version you can run cap rollback for a given environment, and Capistrano will log on to the server and point the code to the previous version that was installed from subversion.

With this approach I only have to back up the variable data, such as the Subversion repo, Capistrano recipes, and PostgreSQL DBs. With Capistrano and config management tools I can roll out a new host in minutes.

| improve this answer | |

I've in the past put both my /etc and /var/www under an svn repo for quick reverts and used tar for incremental backups and full backups.

Rsync by default just ensure that two directory's are in sync but as others pointed out you can script it to have symbolic(or hard) links to older backups if the files has not changed.

No reason why you can't use both.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.