Backup with versioning

backup() { source=$1 ; rsync --relative --force --ignore-errors --no-perms --chmod=ugo=rwX --delete --backup --backup-dir=$(date +%Y%m%d-%H%M%S)_Backup --whole-file -a -v $source/ ~/Backup ; } ; backup /source_folder_to_backup
Apart from an exact copy of your recent contents, also keep all earlier versions of files and folders that were modified or deleted. Inspired by the excellent EVACopy
Sample Output
pascalv@hp:~$ # Backup pictures and photos from my Samsung Galaxy

pascalv@hp:~$ backup() { source=$1 ; rsync --relative --force --ignore-errors --delete --backup --backup-dir=$(date +%Y%m%d-%H%M%S) --whole-file -a -v --no-perms --chmod=ugo=rwX $source/ ~/Backup ; } ; backup /run/user/1000/gvfs/mtp\:host\=%5Busb%3A001%2C004%5D/Phone/DCIM/
sending incremental file list
(new) backup_dir is 20180807-211132
/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C004%5D/Phone/DCIM/Camera/20180703 IMG_4180.jpg
/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C004%5D/Phone/DCIM/Camera/20180703 IMG_4183.jpg
/run/user/1000/gvfs/mtp:host=%5Busb%3A001%2C004%5D/Phone/DCIM/Camera/20180703 IMG_4184.jpg

sent 147,393,695 bytes  received 781 bytes  11,791,558.08 bytes/sec
total size is 147,355,306  speedup is 1.00

pascalv@hp:~$ # Backup my documents in my home folder

pascalv@hp:~$ backup() { source=$1 ; rsync --relative --force --ignore-errors --no-perms --chmod=ugo=rwX --delete --backup --backup-dir=$(date +%Y%m%d-%H%M%S) --whole-file -a -v $source/ ~/Backup ; } ; backup ~/Documents
sending incremental file list
(new) backup_dir is 20180807-213949
deleting home/pascalv/Documents/Test1

sent 824 bytes  received 136 bytes  1,920.00 bytes/sec
total size is 143,084,616  speedup is 149,046.48

pascalv@hp:~$ ls ~/Backup/20180807-213949/home/pascalv/Documents
pascalv@hp:~$ # Evacuated file OK

1 Alternatives + Submit Alt

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: