From 05f986658bc04e2dc514b2c3e7777007cb6fb65c Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Mon, 29 Jan 2018 15:31:27 +0000 Subject: Initial commit --- profiles/backup-archive | 13 +++++++++++++ profiles/backup-cleanup | 4 ++++ profiles/backup-list | 4 ++++ profiles/backup-mysql | 10 ++++++++++ profiles/backup-sync | 19 +++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100755 profiles/backup-archive create mode 100755 profiles/backup-cleanup create mode 100755 profiles/backup-list create mode 100755 profiles/backup-mysql create mode 100755 profiles/backup-sync (limited to 'profiles') diff --git a/profiles/backup-archive b/profiles/backup-archive new file mode 100755 index 0000000..ed72be6 --- /dev/null +++ b/profiles/backup-archive @@ -0,0 +1,13 @@ +#!/bin/sh + +DATE=$(date -u "+%Y%m%d%H%M%S") +SRC="$(hostname).apkovl.tar.gz${SUFFIX}" +DEST="$(hostname).${DATE}.tar.gz${SUFFIX}" + +# Keep a montly copy of the first day of the month +if [ "$(date +%d)" = "01" ]; then + echo "Archiving montly backup" + echo "$SRC" + echo "$DEST" + ssh "$BACKUP_SERVER" install -Dm644 "$FQDN"/week/"$SRC" "$FQDN"/month/"$DEST" +fi diff --git a/profiles/backup-cleanup b/profiles/backup-cleanup new file mode 100755 index 0000000..b590b22 --- /dev/null +++ b/profiles/backup-cleanup @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Removing mysqldump file" +rm -f $BACKUP_CACHE/mysql.sql diff --git a/profiles/backup-list b/profiles/backup-list new file mode 100755 index 0000000..30afb37 --- /dev/null +++ b/profiles/backup-list @@ -0,0 +1,4 @@ +#!/bin/sh +echo "Files included in this backup:" +apk audit --backup --quiet --recursive --check-permissions +echo "" diff --git a/profiles/backup-mysql b/profiles/backup-mysql new file mode 100755 index 0000000..ff6edd6 --- /dev/null +++ b/profiles/backup-mysql @@ -0,0 +1,10 @@ +#!/bin/sh + +if [ -n "$MYSQL_PASSWORD" ]; then + echo "Dumping databases to: $BACKUP_CACHE/mysql.sql" + [ -d "$CACHE_DIR" ] || mkdir -p "$BACKUP_CACHE" + mysqldump -u root -p${MYSQL_PASSWORD} --all-databases -r \ + $BACKUP_CACHE/mysql.sql +else + echo "MySQL password not set, skipping mysqldump." +fi diff --git a/profiles/backup-sync b/profiles/backup-sync new file mode 100755 index 0000000..d4514ea --- /dev/null +++ b/profiles/backup-sync @@ -0,0 +1,19 @@ +#!/bin/sh + +echo "Sending backup to backup server" + +# make sure the destination directory exists +ssh "$BACKUP_SERVER" mkdir -p $FQDN/week + +# get the name of the renamed backup and also rename +# this backup on the remote to prevent dulpicate upload +CURR_BACKUP=$(ls -t "$BACKUP_LOCATION" | sed -n 2p) +if [ -n "$CURR_BACKUP" ]; then + HOSTNAME=$(hostname) + ssh "$BACKUP_SERVER" mv -f \ + $FQDN/week/$HOSTNAME.apkovl.tar.gz${SUFFIX} \ + $FQDN/week/$CURR_BACKUP +fi + +rsync -av --delete-after "$BACKUP_LOCATION/" \ + "$BACKUP_SERVER":"$FQDN"/week -- cgit v1.2.3