I'm trying to set up rsync to send incremental backups to a remote server. The first backup would go to a "backup" folder, then the next backup would send only the changes to a "backup.1" folder, and so on.

I managed to do this locally with the following command, which seemed to be working as described, creating a backup.1 folder on the second sync :

rsync -zaP folder_to_backup /backup  

I then set up a ssh key pair and managed to get rsync working remotely, so I'm now using :

rsync -zaP folder_to_backup myuser@myserver:/home/myuser/backup

The sync does work and the files appear on the remove server. But once I run it a second time, the new files simply get added to the existing "backup" folder, rather than creating a backup.1 folder. I also tried other commands with the -b argument, such as :

rsync -zaPb folder_to_backup myuser@myserver:/home/myuser/backup
rsync -aPb --backup-dir=`date +%s` folder_to_backup myuser@myserver:/home/myuser/backup

But it acts the same in all case. In the last case, the sync still goes to the "backup" folder, the backup-dir argument seems to be ignored completely.

What am I doing wrong?

Edit : Reading the comments, it's possible I got confused somehow when I say "which seemed to be working as described, creating a backup.1 folder on the second sync". That's how I remember it but apparently it's not a feature of rsync?
Instead, I now installed rsnapshot, which is great for incremental backups.

  • Hi @Dino, I tried to reproduce your usage of rsync in the first command and I don't get the result you describe. Are you using this inside a script? if that is the case would you post it? – Jorge Valentini Nov 20 '18 at 1:53
  • @JorgeValentini No, I'm using regular rsync. I checked my shell history and the exact command was "rsync -zaP www/ backup.bak". When I ran it the second time, about one hour had passed and a lot of files had changed in www. They were sent to a backup.bak.1 folder. – Dino Nov 20 '18 at 2:27
  • Also, what version of rsync? rsync --version |grep version Also, are we sure that does what you think it does? --backup-dir=DIR make backups into hierarchy based in DIR – varlogtim Nov 20 '18 at 2:28
  • Nope @Dino... I cannot replicate the behavior you describe. Just a hunch, but may that be a version thing? did you try the rsync locally on myserver? – Jorge Valentini Nov 20 '18 at 2:43
  • Investigate --link-dest – wurtel Nov 20 '18 at 10:42

Your Answer

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

Browse other questions tagged or ask your own question.