Skip to content

Commit

Permalink
initial import from AUR version 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMekkering committed Sep 11, 2017
1 parent dff9ddd commit 2da2faa
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
76 changes: 76 additions & 0 deletions luky-borg-backup
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions luky-borg-backup.conf
Original file line number Diff line number Diff line change
@@ -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 \
# "
8 changes: 8 additions & 0 deletions luky-borg-backup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=LukyLX Incremental Backup
Wants=unit-status-mail@%n.service
Before=unit-status-mail@%n.service

[Service]
Type=oneshot
ExecStart=/usr/bin/luky-borg-backup
10 changes: 10 additions & 0 deletions luky-borg-backup.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Run luky-borg-backup every night

[Timer]
OnCalendar=04:00
AccuracySec=1h
Persistent=yes

[Install]
WantedBy=timers.target

0 comments on commit 2da2faa

Please sign in to comment.