Commit ee497c16 authored by Nils Knappmeier's avatar Nils Knappmeier

Initial checkin

# Backup2l-Setup for Hetzner-Servers
This backup setup assumes the following 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> /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 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 ``
* 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.
# Load settings from the same directory as the run-backup-script
# Computed variables
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"
# 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."
# 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
# 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