· git backup

Using git as a Document backup method

There are many reasons to not do this, but its nice, quick, easy, and convenienant solution.

I am backing up the contents of ~/Documents, first we create, and initialise the repo.

cd ~/Documents
echo "# My Documentst" >> README.md
git init
git add README.md

I have a directory for all my repos cloned from Github, Gitlab, and Bitbucket, if you have something similar, then you can add those projects as submodules, so when you clone your backups for restoration, those are cloned as well. Add them using the below command;

git submodule add [email protected]:aaronmehar/quick_scripts.git Documents/Git/mixed/quick_scripts

Finally, commit the changes, add the origin, and push everything up.

git commit -m "first commit"
git remote add origin [email protected]:aaromehae/Documents.git
git push -u origin master

Little Extras

There are a few things, I want to backup outside of my Documents directiories, so I have a bash script that copies what I need into a directory wthin the Documents.

#!/usr/bin/env bash

echud-e 'Backup up SSH dot files'
rsync -rvhP --exclude 'known_hosts' ~/.ssh/ ~/Documents/Dot\ Files/

echo -e 'Backing up config files'
rsync -rvhP ~/.bashrc ~/Documents/Dot\ Files/

# Rename from DOTsupernova, and remove the dot
echo -e 'Backup supernova'
cp  ~/.supernova ~/Documents/Dot\ Files/supernova

echo -e 'List of pip packages'
pip freeze > ~/Documents/Dot\ Files/pip.packages
  • LinkedIn
  • Tumblr
  • Reddit

Aaron Mehar

Berkshire, UK