I'm trying to make an automated backup of my
/home directory. In theory this is simple by running this in a cronjob:
cd /home git add . git commit -m "nightly backup" git push
where push will push the changes to a remote backup server.
The problem I have is if there is a git repo in the
/home directory e.g.
/home/tom/projects/myproject/.git. The backup task runs and pushes all changes to the server. However, any directories that contain repositories are now blank on the server.
I realise this could be handled with submodules. However, this has several downsides:
Each submodule must be registered with the parent repo (This could be automated but it would be a bit of a pain, recursing into every directory and adding the submodule each time the cron runs)
Non-committed changes from the submodule will not be backed up, this is not desirable behaviour for a backup, I want a live snapshot of all the files as they are at the moment, whether or not they're tracked elsewhere
I realise there are other tools such as rsync to do this, however it would be nice to have git track the changes over time. Is there any way to have git treat other repositories as if they are just normal files (including their .git directory!)
A workaround for this would be running something like this in the cron:
- Recurse into all subirectories
- Look for a .git folder
- Rename .git to something else
- Then run the standard add/commit/push
This will work but will require renaming all the .git folders back during any restoration process. Is there any way to achieve this without this overhead?