Ask Your Question

include top-directory files in a backup

asked 2016-08-12 14:42:37 -0600

wolfv gravatar image

updated 2016-08-16 21:27:35 -0600

I am using gsutil rsync command to run regular backups to Google Cloud Storage. It works very well except that gsutil rsync does not have an "--include" option. So I am looking for a way to include the following files in my backup:


I only want to backup the above files and the ~/Documents/ directory. Maybe put all those files in a ~/scripts/ directory and backup the ~/scripts/ directory. But how would all those applications find their files? Maybe that's not the way to do it. I am open to suggestions.

I am using Fedora 24. I apologize if this is not the right forum to ask the question.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-08-15 18:32:30 -0600

wolfv gravatar image

updated 2016-08-16 21:46:43 -0600

This backs up only .file1 and .file2:

$ ls -A
.file1  .file11  .file2  .file3  x.file2  xfile1
$ /home/wolfv/gsutil/gsutil rsync -n -x '^(?!(\.file1|\.file2)$).*' ~/test_source1/ gs://wolfv-backup-tutorial
Building synchronization state...
Starting synchronization
Would copy file:///home/wolfv/test_source1/.file1 to gs://wolfv-backup-tutorial/.file1
Would copy file:///home/wolfv/test_source1/.file2 to gs://wolfv-backup-tutorial/.file2

"-n" is the gsutil rsync dry-run option.
"-x" is the gsutil rsync exclude option.
Bash does not interpret inside single quotes.
Python regular expression is placed inside the single quotes.
"^" matches only at the beginning of the string.
"?!" is negative lookahead assertion described in
"|" delineates file names.
"\" back slashes escape the "." for hidden files.
"$" matches only at the end of the string.
".*" at the end of the regex is needed to match strings rejected by "?!".

More details are in the Google Cloud Storage backup tutorial.

edit flag offensive delete link more

answered 2016-08-13 14:13:41 -0600

sideburns gravatar image

Actually, the answer is easy if you take it logically: you create links to those files in your ~/scripts directory and back it up along with ~/Documents. Or, if you want to make it really simple, create a ~/Documents/scripts directory so that one backup gets everything.

edit flag offensive delete link more


@sideburns, That's a clever workaround to back up the files. But there is a caveat.
When data is restored from backup, files are where the symlinks were, and the symlinks are lost.
To complete the restoration, the files need to be moved manually and the symlinks remade.

Thank you sideburns, I will use it if that's the best solution.

wolfv gravatar imagewolfv ( 2016-08-13 15:20:04 -0600 )edit

If the links and the original files are both under your home directory, they're presumably in the same partition, meaning that you could use hard links instead. I'm not sure if that would matter during a backup/restore, but it's worth experimenting with to find out. I doubt that it would help, but it's simple enough to check.

sideburns gravatar imagesideburns ( 2016-08-13 15:55:53 -0600 )edit

Question Tools

1 follower


Asked: 2016-08-12 14:42:37 -0600

Seen: 223 times

Last updated: Aug 16 '16