DEV Community

Cover image for rsync - 10 examples in 11 days (Day 06)

Posted on

rsync - 10 examples in 11 days (Day 06)

Day 06

10 examples in 11 days

Add Linux User + Unix date stamp to backup folder

Today's article is a short article I will not talk about an option of rsync, is just a useful syntax that we can attach to the backup destination folder.

In Day 04 I talked about backups and what I will mention today comes very handy when doing backups while synching.


Yes, as you read, adding a linux user can be useful to know who did it and adding a timestamp let's us know when.

Let me show with an example:

  1. Let's see what my Source, Destination and Backup directories have
iamgroot@laptop:~$ ls -F ~/Users
file1.txt  file2.txt  file3.txt
iamgroot@laptop:~$ ls -F ~/Sync
iamgroot@laptop:~$ ls -F ~/backups
Enter fullscreen mode Exit fullscreen mode
  • Source ~/Users has file1.txt, file2.txt and file3.txt
  • Destination ~/Sync is empty
  • Backups ~/backups is empty

Let's now add the current linux User (\$USER) separated by a dash unix timestamp to the backup folder

iamgroot@laptop:~$ rsync -vhrb --backup-dir='/home/iamgroot/backups/'$(date +$USER-%s) --suffix='.bak' ~/Users/ ~/Sync
sending incremental file list

sent 276 bytes  received 73 bytes  698.00 bytes/sec
total size is 36  speedup is 0.10
Enter fullscreen mode Exit fullscreen mode

Let's check each folder again

iamgroot@laptop:~$  ls -F ~/Users && printf -- '-%.0s' {1..10}; echo "" && ls -F ~/Sync && printf -- '-%.0s' {1..10}; echo "" && ls -F ~/backups/ && ls -F ~/backups/iamgroot-1595372929/
file1.txt  file2.txt  file3.txt
file1.txt  file2.txt  file3.txt
file1.txt.bak  file2.txt.bak  file3.txt.bak
Enter fullscreen mode Exit fullscreen mode

Obviously you can add $(date +$USER-%s) as suffix or using how ever you want.

Cool!!!. Now you know a different way to perform a single task

Ok, that'll be for today's example, thanks for reading!!!

Follow, ❤ or 🦄

Top comments (0)