Commit ee497c16 authored by Nils Knappmeier's avatar Nils Knappmeier

Initial checkin

parents
# Backup2l-Setup for Hetzner-Servers
This backup setup assumes the following fstab
```fstab
proc /proc proc defaults 0 0
/dev/md/0 none swap sw 0 0
/dev/md/1 /boot ext3 defaults 0 0
/dev/vgmain/lvmain / ext4 defaults 0 0
//<username>.your-backup.de/backup /mnt/backup-server cifs iocharset=utf8,rw,credentials=/etc/backup-credentials.txt,uid=0,gid=0,file_mode=0660,dir_mode=0770 0 0
```
`dev/vgmain/lvmain` is the partition of which the backup is created. There should be space available for a snapshot in the volume group.
## Setup
* Install backup2l and the cifs-utils.
`sudo apt-get install -y backup2l cifs-utils`
* Make sure the fstab-line of the `/mnt/backup-server` (see above) is part of your fstab.
* The file `/etc/backup-credentials.txt` should contain username and passwort of the backup-store (see https://wiki.hetzner.de/index.php/Backup/en#SAMBA.2FCIFS for details) and have `0600`-permissions.
* Copy the file [backup2l.conf](backup2l.conf) to `/etc/backup2l.conf`
## Process
The following actions will be executed by `run-backup.sh`
* Create a new LVM snapshot of `/dev/vgmain/lvmain`
* Mount this snapshot on `/media/lvmain-snapshot`
* **Create a backup** by running `backup2l` chrooted to `media/lvmain-snapshot`
* Remove all mounts below (or equal) `/media/lvmain-snapshot`
* Remove the LVM snapshot
The last two steps are implemented in a `trap` so that they are also executed, if the backup is aborted. They are also executed before everything else, if the snapshot volume already exists, before starting the backup.
This diff is collapsed.
#!/bin/bash
# Load settings from the same directory as the run-backup-script
SOURCE_LV=/dev/vgmain/lvmain
SNAPSHOT_MOUNT=/media/lvmain-snapshot
# Computed variables
SNAPSHOT_LV=${SOURCE_LV}-snapshot
set -e
# Cleanup hooks
function cleanup {
echo "Removing ${SNAPSHOT_LV} in one second"
sleep 1
# Remove all mounts mounted on the snapshot
for i in $( mount | grep -o "${SNAPSHOT_MOUNT}[^ ]*" | sort -r ) ; do
umount "$i"
done
# remove the snapshot
lvremove -f "${SNAPSHOT_LV}"
}
trap cleanup EXIT
# Cleanup if snapshot device already exists
if [ -e "${SNAPSHOT_LV}" ] ; then
echo "Snapshot ${SNAPSHOT_LV} already exists."
cleanup
fi
# Create directory
mkdir -p "${SNAPSHOT_MOUNT}"
mkdir -p "/var/lib/backup2l"
# Create lvm snapshot of root file system
lvcreate -L10G -s -n "${SNAPSHOT_LV}" "${SOURCE_LV}"
# mount snapshot
mount "${SNAPSHOT_LV}" "${SNAPSHOT_MOUNT}"
# run backup-manager
chroot "${SNAPSHOT_MOUNT}" backup2l --backup
# Cleanup is done by the "trap cleanup EXIT"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment