INIT
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
config
|
||||
software.list
|
||||
backup.log
|
||||
id_backup
|
||||
data/
|
||||
14
after.sh
Executable file
14
after.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#! /bin/bash
|
||||
|
||||
##
|
||||
## Send mail to admin
|
||||
##
|
||||
|
||||
#mail -a "From: "$HOST" Backup <"$HOST"@server.de>" -s "Backup | "$HOST $MAIL < $LOG
|
||||
|
||||
if [ ${global_exit} -ne 0 ];
|
||||
then
|
||||
echo ${global_exit}
|
||||
# curl -X POST 'https://api.telegram.org/bot$TELEGRAM_API_TOKEN/sendMessage?chat_id=$TELEGRAM_CHAT_ID&text="$(cat $LOG)"'
|
||||
wget "https://api.telegram.org/bot$TELEGRAM_API_TOKEN/sendMessage" --post-data="chat_id=$TELEGRAM_CHAT_ID&text='$(cat $LOG)'"
|
||||
fi
|
||||
15
before.sh
Executable file
15
before.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#! /bin/bash
|
||||
|
||||
##
|
||||
## Create list of installed software
|
||||
##
|
||||
|
||||
dpkg --get-selections > $DIR_DATA/software.list
|
||||
|
||||
##
|
||||
## Create database dumps
|
||||
##
|
||||
|
||||
#echo "Creating database dumps ..."
|
||||
#/bin/bash /root/backup/dbdump.sh
|
||||
|
||||
5
config.exp
Normal file
5
config.exp
Normal file
@@ -0,0 +1,5 @@
|
||||
REPOSITORY="ssh://borg@backupserver:22/media/hdd/backup"
|
||||
PASSPHRASE=""
|
||||
TELEGRAM_API_TOKEN=""
|
||||
TELEGRAM_CHAT_ID="@..."
|
||||
|
||||
97
run.sh
Executable file
97
run.sh
Executable file
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
|
||||
##
|
||||
## Save backup to directory named after hostname
|
||||
##
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
||||
DIR_DATA=$DIR"/data"
|
||||
|
||||
# load config
|
||||
. $DIR/config
|
||||
|
||||
LOG=$DIR"/backup.log"
|
||||
export BORG_REPO=$REPOSITORY
|
||||
export BORG_PASSPHRASE=$PASSPHRASE
|
||||
export BORG_RSH="ssh -i $DIR/id_backup"
|
||||
|
||||
##
|
||||
## Write output to logfile
|
||||
##
|
||||
|
||||
exec > >(tee -i ${LOG})
|
||||
exec 2>&1
|
||||
|
||||
# some helpers and error handling:
|
||||
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
|
||||
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
|
||||
|
||||
echo "###### Starting backup on $(date) ######"
|
||||
|
||||
. $DIR/before.sh
|
||||
|
||||
##
|
||||
## Sync backup data
|
||||
##
|
||||
|
||||
echo "Syncing backup files ..."
|
||||
borg create \
|
||||
--verbose \
|
||||
--filter AME \
|
||||
--list \
|
||||
--stats \
|
||||
--show-rc \
|
||||
--compression lz4 \
|
||||
--exclude-caches \
|
||||
--exclude '/home/*/.cache/*' \
|
||||
--exclude '/var/cache/*' \
|
||||
--exclude '/var/tmp/*' \
|
||||
\
|
||||
::'{hostname}-{now}' \
|
||||
/etc \
|
||||
/home \
|
||||
/root \
|
||||
/var \
|
||||
$DIR_DATA \
|
||||
/media/data/live
|
||||
|
||||
backup_exit=$?
|
||||
|
||||
echo "###### Finished backup on $(date) ######"
|
||||
|
||||
echo "###### Pruning repository on $(date) ######"
|
||||
|
||||
# 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 machines' archives also:
|
||||
|
||||
borg prune \
|
||||
--list \
|
||||
--prefix '{hostname}-' \
|
||||
--show-rc \
|
||||
--keep-daily 7 \
|
||||
--keep-weekly 4 \
|
||||
--keep-monthly 6 \
|
||||
|
||||
prune_exit=$?
|
||||
|
||||
echo "###### Finished pruning on $(date) ######"
|
||||
|
||||
# use highest exit code as global exit code
|
||||
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
|
||||
|
||||
if [ ${global_exit} -eq 1 ];
|
||||
then
|
||||
echo "Backup and/or Prune finished with a warning"
|
||||
fi
|
||||
|
||||
if [ ${global_exit} -gt 1 ];
|
||||
then
|
||||
echo "Backup and/or Prune finished with an error"
|
||||
fi
|
||||
|
||||
. $DIR/after.sh
|
||||
|
||||
exit ${global_exit}
|
||||
|
||||
Reference in New Issue
Block a user