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

rsync - 10 examples in 11 days (Day 06)

jmr_code_social profile image Jorge Marquez ・2 min read

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.

So, Adding a USER + UNIX TIMESTAMP?

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
  • 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
file1.txt
file2.txt
file3.txt

sent 276 bytes  received 73 bytes  698.00 bytes/sec
total size is 36  speedup is 0.10

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
----------
iamgroot-1595372929/
file1.txt.bak  file2.txt.bak  file3.txt.bak

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 🦄

Discussion

pic
Editor guide