Commit 1d1561b4 authored by Michael Iseard's avatar Michael Iseard
Browse files

Initial commit

parents
Pipeline #5 failed with stages
IM_BACKUP_SOURCE="/home/michael/docker/"
IM_BACKUP_DESTINATION="/nfs/usbdrive/"
IM_NFS_SOURCE="192.168.1.1:/media/usbdrive/"
BORG_PASSPHRASE="changeme"
\ No newline at end of file
#!/bin/bash
# VARIABLES
containers=$(docker ps -q)
name=$(date +"%Y%m%d")
done=$(echo -e "\e[32mdone\e[0m")
fail=$(echo -e "\e[31mfail\e[0m")
error=$(echo -e "\e[31merror\e[0m")
dots='....'
echo "Starting backup - "$name > $name.log
# Prevent colour codes in log file
exec > >( tee >( sed 's/\x1B\[[0-9;]*[JKmsu]//g' >> $name.log ) )
# LOAD ENVS
if [ -f ".env" ]; then
export $(egrep -v '^#' .env | xargs) > /dev/null
else
echo $error ".env file not found"
exit 1
fi
# FUNCTIONS
function check_result() {
if [ $? -eq 0 ]; then
echo $done
else
echo "$fail(exit code: $?)"
exit 1
fi
}
if [[ ! -z "$IM_NFS_MOUNT_POINT" || "$IM_NFS_SOURCE" ]]; then
echo -n 'Mounting NFS.......'$dots
sudo mount $IM_NFS_SOURCE $IM_BACKUP_DESTINATION
check_result
fi
if [ ! -z "$containers" ]; then
echo -n 'Stopping containers'$dots
docker stop $containers > /dev/null 2>&1
check_result
fi
echo -n 'Sending backup.....'$dots
borg create $IM_BACKUP_DESTINATION::$name $IM_BACKUP_SOURCE
check_result
echo -n 'Pruning backups....'$dots
borg prune -sv -d7 -w4 -m12 --show-rc $IM_BACKUP_DESTINATION > /dev/null 2>&1
check_result
if [[ ! -z "$IM_NFS_MOUNT_POINT" || "$IM_NFS_SOURCE" ]]; then
echo -n 'Unmounting backup..'$dots
sudo umount /nfs/BACKUP1/
check_result
fi
if [ ! -z "$containers" ]; then
echo -n 'Starting containers'$dots
docker start $containers > /dev/null 2>&1
check_result
fi
\ 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