DEV Community

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

Posted on

2

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.

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

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
----------
iamgroot-1595372929/
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 🦄

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay