summaryrefslogtreecommitdiff
path: root/.local/bin/backups/assimilate
blob: ba31baa3e23820d5f2322a2c04dcd4cdf79f4850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
# Full system backup with borg

# Validate argument - should either be onsite or offsite to specify location
ERRMSG="error: please specify either onsite or offsite"
[ $# -ne 1 ] && echo $ERRMSG && exit 1
[ "$1" != "onsite" -a "$1" != "offsite" ] && echo $ERRMSG && exit 1

# Set variables
LOCATION="$1"
SUDO_OPTS="--preserve-env=BORG_PASSCOMMAND,PASSWORD_STORE_DIR"
CREATE_OPTS="--warning --stats --show-rc --exclude-caches --one-file-system"
LOG="$HOME/.config/borg/log"

# Hack to get repository passphrase from pass
# The passcommand will be invoked as root, so use sudo to run it as the user calling the script
# who owns the password store.  The environmental variable PASSWORD_STORE_DIR is passed through
# SUDO_OPTS to the borg commands, and then passed to this command from the borg command
# by the same means.  This allows custom password store locations to work with this script.
export BORG_PASSCOMMAND="sudo $SUDO_OPTS -u $USER pass Borg-Backup/$(hostname)-$LOCATION"

# Backup root partition
sudo $SUDO_OPTS borg create $CREATE_OPTS \
		--exclude '/dev/*' 		\
		--exclude '/proc/*' 	\
		--exclude '/sys/*'		\
		--exclude '/tmp/*'		\
		--exclude '/mnt/*'		\
		--exclude '/media/*'	\
		"/mnt/onsite-backup/$(hostname)::root-{now:%Y-%m-%d}" / 2>>$LOG

# Backup boot parition
sudo $SUDO_OPTS borg create $CREATE_OPTS \
		"/mnt/onsite-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG

# Backup home partition
sudo $SUDO_OPTS borg create $CREATE_OPTS \
		"/mnt/onsite-backup/$(hostname)::home-{now:%Y-%m-%d}" /home 2>>$LOG

# Backup var partition
sudo $SUDO_OPTS borg create $CREATE_OPTS \
		"/mnt/onsite-backup/$(hostname)::var-{now:%Y-%m-%d}" /var 2>>$LOG