Raspberry Pi Update Server Part One

February 09, 2019, Sam Erickson

catagories: linux ssh raspberry-pi

Getting started

Note: This is not a tutorial. I will eventually sit down and type up a tutorial, but for now this is just my though process behind the project.

The idea is to run systematic backups of my files, mimicking Apples Time Machine utility where backups are taken hourly, but saved in a very specific way.

Backup Matrix**

The Plan

The plan is to make this project modular. That is broken up into smaller subsections simplifying the project, and making the components more robust and useful to other potential projects.

Each backup should use symbolic links so as not to use up too much storage. This is handled automatically using the sys-link functionality of rsync.

Setting Up a Different SSH Identity File

While I was messing around with commands, trying to figure out how to make this work in the way that I wanted, I discovered two issues:

  1. I have to enter my password at least twice to do a backup, which is not ideal.
  2. The command gets really long really quickly

While tying to understand using a different ssh key then the default ~/.ssh/id_rsa.pub, which I needed to stay in place for other ssh servers that I use. At first I was using the -i flag for ssh allowing me to select the identity file within the command, when I stumbled upon someone else’s ssh config file. This turns out to be an answer to both my problems as well as solving one that I did not know I had until it was solved, which was security issues with sharing the code containing all my ssh information. Now, that information is not inertially private, but no information is safer. So now I can keep all information about my personal servers, while keeping all the code open source, and easily replicated.

SSH config

Right now you have to specify your ssh server in your ~/.ssh/config file like so:

Host		alias-hostname
Hostname	server.address.com
IdentityFile	~/.ssh/id_rds.xxx
Port		XXXX
User		name-of-user-account-on-remote-machine

You can ommit Port and IdentityFile if you are using the defaults of 22 and ~/.ssh/id_rsa.pub.

The script

The project is live at Github, and here is the actual code that I have come up with so far:

#!/bin/bash

## CONFIG ##

# Rsync option:
#	-a	:specifies archive mode, preserve permissions and file states
#	-z	:compress
#	-P	:show progress
#
# For more options look at the man pages: man rsync
opts="-azP"

# Files to be excluded in the backup process
exclude='--exclude={\
	"/dev/*",\
	"/proc/*",\
	"/sys/*",\
	"/tmp/*",\
	"/run/*",\
	"/mnt/*",\
	"/media/*",\
	"/lost+found"\
	}'

# The file to backup, in this case I want full system backups so I am backing
#	up the root. Make sure not to include /proc/ as it will use up 3Tb or
#	more of space for an usless file.
src="/"

# The location of you backup folder on the remote machine
loc="/backups/arch-macbook"

# The name of the actual backup in the form "backup-year-month-day.hour:minut
dest="$loc/backup-$(date +%Y-%m-%d.%H:%m)"

# The location of the last backup
link="--link-dest=$loc/current"

# The command that does all the heavy lifting for you
rsync $opts $link $src pi:$dest

# Create a link to keep track of the last backup
ssh pi "ln -sf $dest $loc/current"

Current plan map:

Functionality that still needs to be figured out:

Functionality Wish List

Summary

There is still lots of playing around with rsync as well as reading man pages before I am ready to take on the next step, but at least I can do full system backups with hard-links over ssh in the mean time.