summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Mekkering2017-07-21 08:57:55 +0200
committerAlex Mekkering2017-07-21 08:57:55 +0200
commitc12ae1dbfe115321fbfc53ac7f7b602502902848 (patch)
tree6c06dfd50fadb2e462d0148a33787706a72389a9
downloadaur-c12ae1dbfe115321fbfc53ac7f7b602502902848.tar.gz
Initial commit
-rw-r--r--.SRCINFO19
-rw-r--r--PKGBUILD27
-rwxr-xr-xluky-borg-backup76
-rw-r--r--luky-borg-backup.conf26
-rw-r--r--luky-borg-backup.service6
-rw-r--r--luky-borg-backup.timer10
6 files changed, 164 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 00000000000..cb3c076241a
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,19 @@
+pkgbase = luky-borg-backup
+ pkgdesc = Automated backup scripts using Borg Backup, systemd and optionally Nextcloud/ownCloud/Stack
+ pkgver = 1.0.0
+ pkgrel = 1
+ arch = any
+ license = MIT
+ depends = borg
+ optdepends = owncloud-client: For backing up to Nextcloud/ownCloud/Stack
+ source = luky-borg-backup
+ source = luky-borg-backup.service
+ source = luky-borg-backup.timer
+ source = luky-borg-backup.conf
+ md5sums = e98689841afd51b0f8572085aa2d1917
+ md5sums = 1d2f47ca460ab2d477b3753f9a86ae07
+ md5sums = 5b876c8ae21d8ce159c161993e97536d
+ md5sums = b1ef1610ffd6f3dd792da4869910a917
+
+pkgname = luky-borg-backup
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 00000000000..5c00d4087a5
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,27 @@
+# Maintainer: Alex Mekkering <amekkering at gmail dot com>
+
+pkgname=luky-borg-backup
+
+pkgver=1.0.0
+pkgrel=1
+pkgdesc="Automated backup scripts using Borg Backup, systemd and optionally Nextcloud/ownCloud/Stack"
+arch=(any)
+license=('MIT')
+depends=('borg')
+optdepends=('owncloud-client: For backing up to Nextcloud/ownCloud/Stack')
+source=('luky-borg-backup'
+ 'luky-borg-backup.service'
+ 'luky-borg-backup.timer'
+ 'luky-borg-backup.conf'
+)
+md5sums=('e98689841afd51b0f8572085aa2d1917'
+ '1d2f47ca460ab2d477b3753f9a86ae07'
+ '5b876c8ae21d8ce159c161993e97536d'
+ 'b1ef1610ffd6f3dd792da4869910a917')
+
+package() {
+ install -D -m 755 "$srcdir/luky-borg-backup" "$pkgdir/usr/bin/luky-borg-backup"
+ install -D -m 644 "$srcdir/luky-borg-backup.service" "$pkgdir/usr/lib/systemd/system/luky-borg-backup.service"
+ install -D -m 644 "$srcdir/luky-borg-backup.timer" "$pkgdir/usr/lib/systemd/system/luky-borg-backup.timer"
+ install -D -m 644 "$srcdir/luky-borg-backup.conf" "$pkgdir/etc/luky-borg-backup.conf"
+}
diff --git a/luky-borg-backup b/luky-borg-backup
new file mode 100755
index 00000000000..bb63eb5312e
--- /dev/null
+++ b/luky-borg-backup
@@ -0,0 +1,76 @@
+#!/bin/sh
+CONFFILE=/etc/luky-borg-backup.conf
+. $CONFFILE
+
+if [ -z "$REPOSITORY" ]; then
+ echo "ERROR: No REPOSITORY set. Please edit $CONFFILE"
+ exit
+fi
+
+# Try to mount the MOUNTPOINT first (if one exists)
+premounted="1" # assume all mounts were already in place before we started
+mounted="1" # assume a mounted state until proven otherwise
+if [ ! -z "$MOUNTPOINT" ]; then
+ premounted="0"
+ mounted="0"
+
+ if [ `mount | grep -c "$MOUNTPOINT"` -ne "0" ]; then
+ premounted="1"
+ mounted="1"
+ echo "$MOUNTPOINT was already mounted..."
+ else
+ echo "Mounting $MOUNTPOINT..."
+ mount "$MOUNTPOINT"
+ if [ "$?" -ne "0" ]; then
+ echo "ERROR: $MOUNTPOINT could not be mounted!"
+ else
+ echo " Mounted $MOUNTPOINT!"
+ mounted="1"
+ fi
+ fi
+fi
+
+if [ "$mounted" -eq "1" ]; then
+ # Backup all necessary files and directories using deduplication and lz4 conpression
+
+ echo
+ echo "Backing up to $REPOSITORY..."
+ borg create -v -s --noatime -C lz4 $REPOSITORY::'{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' $SOURCES
+ echo " Backed up to $REPOSITORY!"
+ echo
+
+ # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
+ # archives of THIS machine. The '{hostname}-' prefix is very important to
+ # limit prune's operation to this machine's archives and not apply to
+ # other machine's archives also.
+ borg prune -v --list $REPOSITORY --prefix '{hostname}-' --keep-daily=7 --keep-weekly=4 --keep-monthly=12
+
+ if [ ! -z "$CLOUDFOLDER" ]; then
+ echo
+ echo "Syncing $REPOSITORY with $CLOUDFOLDER..."
+ owncloudcmd -u $CLOUDUSER -s -p $CLOUDPASSWORD -h $REPOSITORY $CLOUDFOLDER
+ echo " Synced $REPOSITORY with $CLOUDFOLDER!"
+ fi
+
+ if [ ! -z "$MOUNTPOINT" ]; then
+ echo
+ echo "=============================================="
+ echo "Usage of filesystem at $MOUNTPOINT after backing up:"
+ echo "----------------------------------------------"
+ df -hT ${MOUNTPOINT}
+ echo "=============================================="
+ echo
+
+ if [ "$premounted" -eq "0" ]; then
+ echo "Unmounting $MOUNTPOINT..."
+ umount "$MOUNTPOINT"
+ if [ "$?" -eq "0" ]; then
+ echo " Unmounted $MOUNTPOINT"
+ else
+ echo "ERROR: $MOUNTPOINT could not be unmountedi!"
+ fi
+ else
+ echo "Keeping $MOUNTPOINT mounted because it was already mounted!"
+ fi
+ fi
+fi
diff --git a/luky-borg-backup.conf b/luky-borg-backup.conf
new file mode 100644
index 00000000000..1341affd89c
--- /dev/null
+++ b/luky-borg-backup.conf
@@ -0,0 +1,26 @@
+# Optionally, set a MOUNTPOINT to mount at start and unmount at finish
+# (if it wasn't mounted already at start). i.e.:
+# MOUNTPOINT=/mnt
+
+# Optionally set the Stack (or Owncloud or Nextcloud) folder to sync backups to. i.e.:
+# CLOUDFOLDER="https://transip.stackstorage.com/remote.php/webdav/backup"
+
+# Optionally set a username and password for Stack (or Owncloud or Nextcloud). i.e.:
+# CLOUDUSER="admin"
+# CLOUDPASSWORD="password"
+
+# Optionally export the BORG_PASSPHRASE to be able to non-interactively create an encrypted backup (Recommended). i.e.:
+# export BORG_PASSPHRASE='secret'
+
+# Optionally, export other BORG Environment Variables. i.e.:
+# export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes # non-interactively accept relocation of a repository
+
+# Set the borg REPOSITORY to backup to. i.e.:
+# REPOSITORY="$MOUNTPOINT/backup"
+
+# Define the folders/files to include/exclude. i.e.:
+# SOURCES="\
+# /etc \
+# /srv/http \
+# -e /etc/mtab \
+# "
diff --git a/luky-borg-backup.service b/luky-borg-backup.service
new file mode 100644
index 00000000000..9ff1c9db176
--- /dev/null
+++ b/luky-borg-backup.service
@@ -0,0 +1,6 @@
+[Unit]
+Description=LukyLX Incremental Backup
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/luky-borg-backup
diff --git a/luky-borg-backup.timer b/luky-borg-backup.timer
new file mode 100644
index 00000000000..6785083387a
--- /dev/null
+++ b/luky-borg-backup.timer
@@ -0,0 +1,10 @@
+[Unit]
+Description=Run luky-borg-backup every night
+
+[Timer]
+OnCalendar=04:00
+AccuracySec=1h
+Persistent=yes
+
+[Install]
+WantedBy=timers.target