I had to re-install so I documented my process. In this post, I focus on getting my data backed up so that I can restore it after the installation.
Whatever isn't in git gets archived. This is mainly my home directory. I want it backed up to my VM at CloudAfrica and to my external HDD. If I have learned anything in this process it is that my SSH keys are the most vital piece of bits that I own and that I need one copy in a safe location. Whatever safe means in this world.
tar cpzvf <archive>.tar.gz /home/<username>
rsync -avzh <username>@<host>:/path/to/copy/to/<archive>.tar.gz /path/to/copy/from/<archive>.tar.gz
I had a few permissions hiccups trying to tar my home directory so I took extra steps to tackle these problems.
I use my own remote git repository for directories that contain sensitive information. I followed these instructions to get set up.
Create a git
user and allow ssh
access to authorized users. On the local machine copy the public key
cat ~/.ssh/id_rsa.pub
(or whichever public key you use) and paste it into .ssh/authorized_keys
after it
has been created.
ssh <username>@<host>
sudo adduser git
su git
mkdir /.ssh && chmod 700 /.ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
Create the .git
project and initialize it.
cd /srv/git
mkdir project.git
cd project.git
git init --bare
Configure the git repo locally and point to the newly created remote repository.
cd /home/<user>/path/to/project
git init
git add .
git commit -m "Initial commit"
git remote add origin git@<host>:/srv/git/project.git
git push origin master
If you have problems pushing, check that the directory permissions are not assigned to root ls -lah
.
Assign the files and folders to git using sudo chown git *
Let's take a practical example: I want to store my Gnote notes to my remote repository.
save-gnote
and add it to git. Make it add all
unstaged files in the gnote directory and commit them using a timestamp in the commit message then push to origin.#!/bin/bash
cd /home/<user>/.local/share/gnote
git add .
git commit -m "Backup $(date +%s)"
git push origin master
chmod a+x save-gnote
.ln -s /home/<user>/.local/share/gnote/save-gnote /usr/local/bin/save-gnote
save-gnote
from any directory in the terminal.