blob: 64f39b0e2245f089dced965b822886ddc6042353 (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/bin/bash
# Fast backup using rsync
#
# This script is meant to be executed manually every so often (weekly, monthly).
# If an automatic solution where to be made (e.g., run daily via cron job).
# Then make sure the rsync target is always the same (e.g., minipc:/mnt/backup)
# and the `--delete` flag is NOT used (you'll need to figure out a way to
# "purge" duplicated files in the backup storage every so often).
#
# Steps:
# 1. Connect external storage device and get the block device path (`lsblk`)
# 2. Run this script
#
# See also: http://wiki.pulse15/index.php?title=Backup
if [ $# -ne 2 ]; then
echo "Usage: $(basename "$0") /dev/sdX backup"
exit 1
fi
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root."
exit 1
fi
rsync_options="-auvP --delete"
# path of the device (block device file) (e.g., /dev/sda)
device=$1
# cryptsetup name (e.g., backup)
name=$2
# FIXME
# Everything breaks if `name` or `device` contain spaces. Exit if that's the
# case.
cryptsetup open --type luks $device $name
if [ $? -ne 0 ]; then
# bad device
exit 1
fi
mount /dev/mapper/$name /mnt/$name
# TODO
# Stop backing up /var. Backup is just for Postgres and Mediawiki.
# `/var` is used by too many applications. Specialy pacman that clutters it
# with cached binaries.
rsync $rsync_options /var /mnt/$name # <10G
rsync $rsync_options /home /mnt/$name # <900G
rsync $rsync_options /etc /mnt/$name # <20M
echo "Backup complete."
df -h
umount /mnt/$name
cryptsetup close $name
echo "All done. Check \`$ lsblk\` before unplugging the storage device."
|