backing up files
backing up a local Git repository
Note
- foobar represents the name of the relevant Git repository to be backed up.
- /foo/bar/baz/foobar represents the directory containing the relevant Git repository to be backed up.
- foobar.bundle represents the intermediate Git bundle to be created during the course of backing up the relevant Git repository.
- /baz/bar/foo/foobar represents the directory containing a backup of the relevant Git repository.
Use cd "/foo/bar/baz/foobar" && git bundle create "/tmp/foobar.bundle" --all && git clone "/tmp/foobar.bundle" "/baz/bar/foo/foobar" to back up Git data, excluding any unstaged changes. Then use rsync -c -r -s -t -v --progress --exclude="/.git/" --exclude="/.gitignore/" "/foo/bar/baz/foobar/" "/baz/bar/foo/foobar"
Additional option
In rsync, the -n option enables a dry run, producing information on how the backup would be performed without making any changes to the directory containing a backup of the relevant Git repository.
explanation
Note
This is an incomplete explanation.
- The
-coption enables the checksum-based file skipping. - The
-roption enables recursion. - The
-soption disables space-splitting. - The
-toption preserves file modification time. - The
-voption increases verbosity. - The
--exclude="/.git/"and--exclude="/.gitignore/"options exclude the.gitdirectory and.gitignorefile. - The
--progressoption enables the displaying of transfer progress.
prior work
- The bulk of the rsync portion of the script was generated by grsync.
- The method of using
git-bundlewas introduced to me by an answer to “Backup a GitHub repository” on Stack Overflow by VonC and an answer to “How to backup a local Git repository?” on Stack Overflow by VonC. - The method of using
git-clonewas introduced to me by an answer on Stack Overflow by fbicknel.
licensing
No rights reserved: CC0 1.0.