aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlo Landmeter <clandmeter@alpinelinux.org>2018-07-11 08:49:49 +0000
committerCarlo Landmeter <clandmeter@alpinelinux.org>2018-07-11 11:00:32 +0000
commit9cd4f285688a1f92684b7dda9724759b66edf656 (patch)
tree5d8793d3ed680120e2ae2ffafb39b1abbcbd8863
parent92f3d399ca9da2dac81ac193df830c5f55036dd4 (diff)
downloadalpine-backup-9cd4f285688a1f92684b7dda9724759b66edf656.tar.bz2
alpine-backup-9cd4f285688a1f92684b7dda9724759b66edf656.tar.xz
various changes
- make domain name configurable - prepend RBU to global veriables - cleanup
-rwxr-xr-xalpine-backup21
-rwxr-xr-xprofiles/backup-archive2
-rwxr-xr-xprofiles/backup-cleanup2
-rwxr-xr-xprofiles/backup-mysql4
-rwxr-xr-xprofiles/backup-pgsql4
-rwxr-xr-xprofiles/backup-sync13
-rw-r--r--rbu.conf10
7 files changed, 28 insertions, 28 deletions
diff --git a/alpine-backup b/alpine-backup
index fb6549e..8e6ffbf 100755
--- a/alpine-backup
+++ b/alpine-backup
@@ -19,26 +19,25 @@ else
die "Cannot read $RBU_CONF"
fi
-if [ -n "$BACKUP_LOCATION" ] && [ -n " $BACKUP_CACHE" ]; then
- mkdir -p "$BACKUP_LOCATION" "$BACKUP_CACHE"
+if [ -n "$RBU_LOCATION" ] && [ -n " $RBU_CACHE" ]; then
+ mkdir -p "$RBU_LOCATION" "$RBU_CACHE"
else
- die "Error: BACKUP_LOCATION and/or BACKUP_CACHE are not set."
+ die "Error: RBU_LOCATION and/or RBU_CACHE are not set."
fi
# set the suffix of backup files when ecryptions is enabled
[ -n "$ENCRYPTION" ] && export SUFFIX=".$ENCRYPTION"
# convert hostname to intra FQDN
-HOSTNAME=$(hostname)
-if [ -n "$HOST" ]; then
- export FQDN="${HOSTNAME}.${HOST}.intra.alpinelinux.org"
+if [ -n "$RBU_HOST" ]; then
+ export FQDN="$(hostname).${RBU_HOST}.${RBU_DOMAIN}"
else
- export FQDN="${HOSTNAME}.intra.alpinelinux.org"
+ export FQDN="$(hostname).${RBU_DOMAIN}"
fi
START_TS=$(date +%s)
-LOGFILE="$BACKUP_CACHE/$FQDN-$(date -u "+%Y%m%d%H%M%S").log"
+LOGFILE="$RBU_CACHE/$FQDN-$(date -u "+%Y%m%d%H%M%S").log"
lbu_commit >>"$LOGFILE" 2>&1
ret=$?
@@ -47,13 +46,13 @@ SIZE=0
STATUS=failed
if [ $ret = 0 ]; then
- BACKUP="$BACKUP_LOCATION/$(hostname).apkovl.tar.gz${SUFFIX}"
+ BACKUP="$RBU_LOCATION/$(hostname).apkovl.tar.gz${SUFFIX}"
SIZE=$(stat -c %s $BACKUP)
STATUS=success
fi
-ssh "$BACKUP_SERVER" mkdir -p $FQDN/logs
-scp -q $LOGFILE "$BACKUP_SERVER:$FQDN/logs"
+ssh "$RBU_SERVER" mkdir -p $FQDN/logs
+scp -q $LOGFILE "$RBU_SERVER:$FQDN/logs"
PAYLOAD=$(printf '{ "status": "%s", "size": %u, "duration": %u }' "$STATUS" "$SIZE" "$DURATION")
JSON=$(printf '{ "host": "%s", "key": "backup", "payload": %s }' "$FQDN" "$PAYLOAD")
diff --git a/profiles/backup-archive b/profiles/backup-archive
index 7d7a81a..f9e0be7 100755
--- a/profiles/backup-archive
+++ b/profiles/backup-archive
@@ -11,5 +11,5 @@ DEST="$(hostname).${DATE}.tar.gz${SUFFIX}"
if [ "$(date +%d)" = "01" ]; then
echo "Archiving montly backup"
- ssh "$BACKUP_SERVER" install -Dm644 "$FQDN"/week/"$SRC" "$FQDN"/month/"$DEST"
+ ssh "$RBU_SERVER" install -Dm644 "$FQDN"/week/"$SRC" "$FQDN"/month/"$DEST"
fi
diff --git a/profiles/backup-cleanup b/profiles/backup-cleanup
index b590b22..0199aaa 100755
--- a/profiles/backup-cleanup
+++ b/profiles/backup-cleanup
@@ -1,4 +1,4 @@
#!/bin/sh
echo "Removing mysqldump file"
-rm -f $BACKUP_CACHE/mysql.sql
+rm -f $RBU_CACHE/mysql.sql
diff --git a/profiles/backup-mysql b/profiles/backup-mysql
index 3c4e232..097f99b 100755
--- a/profiles/backup-mysql
+++ b/profiles/backup-mysql
@@ -1,9 +1,9 @@
#!/bin/sh
if [ -n "$MYSQL_PASSWORD" ]; then
- echo "Dumping databases to: $BACKUP_CACHE/mysql.sql"
+ echo "Dumping databases to: $RBU_CACHE/mysql.sql"
mysqldump -u root -p${MYSQL_PASSWORD} --all-databases -r \
- $BACKUP_CACHE/mysql.sql
+ $RBU_CACHE/mysql.sql
else
echo "MySQL password not set, skipping mysqldump."
fi
diff --git a/profiles/backup-pgsql b/profiles/backup-pgsql
index 89fa6a3..dad9401 100755
--- a/profiles/backup-pgsql
+++ b/profiles/backup-pgsql
@@ -6,8 +6,8 @@
# Set GZIP to pigz for multi core compression (if installed)
if [ -n "$PGPASSWORD" ]; then
- echo "Dumping PostgreSQL database to: $BACKUP_CACHE"
- pg_dump | ${GZIP:-gzip} > "$BACKUP_CACHE"/dump.sql.gz
+ echo "Dumping PostgreSQL database to: $RBU_CACHE"
+ pg_dump | ${GZIP:-gzip} > "$RBU_CACHE"/dump.sql.gz
else
echo "PostgreSQL password not set, skipping pg_dump."
fi
diff --git a/profiles/backup-sync b/profiles/backup-sync
index d4514ea..394d667 100755
--- a/profiles/backup-sync
+++ b/profiles/backup-sync
@@ -3,17 +3,16 @@
echo "Sending backup to backup server"
# make sure the destination directory exists
-ssh "$BACKUP_SERVER" mkdir -p $FQDN/week
+ssh "$RBU_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)
+CURR_BACKUP=$(ls -t "$RBU_LOCATION" | sed -n 2p)
if [ -n "$CURR_BACKUP" ]; then
- HOSTNAME=$(hostname)
- ssh "$BACKUP_SERVER" mv -f \
- $FQDN/week/$HOSTNAME.apkovl.tar.gz${SUFFIX} \
+ ssh "$RBU_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
+rsync -av --delete-after "$RBU_LOCATION/" \
+ "$RBU_SERVER":"$FQDN"/week
diff --git a/rbu.conf b/rbu.conf
index c54e2af..797adb2 100644
--- a/rbu.conf
+++ b/rbu.conf
@@ -6,14 +6,16 @@ export PASSWORD=mysecurepassword
export LBU_BACKUPDIR=/var/lib/backup
# amount of backups to store
export BACKUP_LIMIT=7
+# (intranet) domain name
+export RBU_DOMAIN=domain.tld
# if this host is a guest set HOST to hostname of host
-# export HOST=
+# export RBU_HOST=
# the location of the backup cache
-export BACKUP_CACHE=/var/cache/backup
+export RBU_CACHE=/var/cache/backup
# backup directory to be picked up by pre script
-export BACKUP_LOCATION="$LBU_BACKUPDIR"
+export RBU_LOCATION="$LBU_BACKUPDIR"
# ssh backup server to send backups to
-export BACKUP_SERVER="user@backupserver.tld"
+export RBU_SERVER="user@backupserver.tld"
# Custom profile settings