Including a hidden directory in an rsync backup - Help please

Commissario
Joined
16 Oct 2002
Posts
343,947
Location
In the radio shack
Hi folks,

I run an rsync backup of a directory from a Pi to my NAS on a nightly basis and I've just realised that the hidden .git directory within /home/sysop/spidr isn't being copied.

The NAS is mounted at /home/pi/spiderback and backups go into a 'spider' directory in there which is just the date and time.

a41xlgA.png



This is the command I'm running nightly via cron.

Code:
rsync -aH /home/sysop/spider/ /home/pi/spiderback/spider/"$(date +'%Y-%m-%d-%H-%M-%S')"/

I've been trying with little success to make it copy that hidden directory as well.

Can anyone help please?

Thanks.
 
To include hidden directories in an rsync backup, you can use the -a (archive) option, which preserves the directory structure and attributes, and the --include option to specify hidden directories. Here’s an example command:

rsync -av --include='*/' --include='.*' --exclude='*' /source/directory/ /destination/directory/


This command does the following:


  • -a: Enables archive mode, which preserves symbolic links, permissions, timestamps, and other attributes.
  • --include='*/': Includes all directories.
  • --include='.*': Includes all hidden files and directories.
  • --exclude='*': Excludes all other files and directories not explicitly included.

Make sure to replace /source/directory/ and /destination/directory/ with your actual source and destination paths.
 
Yes, I know that but I can’t get my head around it. I’m after someone to actually fettle my command, not just quote the man page.
 
If you try:

Code:
rsync -aH --include='*' /home/sysop/spider/ /home/pi/spiderback/spider/"$(date +'%Y-%m-%d-%H-%M-%S')"/

That should include all directories, hidden or otherwise.
 
Back
Top Bottom