initial commit

This commit is contained in:
Pratik
2019-10-05 21:01:44 +05:30
commit 86b6e86433
3 changed files with 455 additions and 0 deletions

97
backup-systemonly.sh Executable file
View File

@@ -0,0 +1,97 @@
#!/bin/sh
backup_name=systemonly
backup_dir=/backups/borg/$backup_name/
log_dir=/backups/log/
unique_identifier=Manjaro18
#########################################################################
readonly backup_name
readonly backup_dir
readonly log_dir
readonly unique_identifier
# Setting this, so you won't be asked for your repository passphrase:
export BORG_PASSPHRASE='d00x^UXryuEYTwPuZwQh'
# Setting this, so the repo does not need to be given on the commandline:
export BORG_REPO=$backup_dir
# some helpers and error handling:
log_file=$log_dir$backup_name-$(date +%d%m%Y-%H%M%S)
readonly log_file
# if borg is currently running - stop sync
if [ $(pidof borg | wc -w) -eq 1 ]
then
echo "Another Backup is currently running. Exiting." >> $log_file 2>&1
exit 2
fi
info() { printf "\n%s %s\n\n" "$( date )" "$*" >> $log_file 2>&1; }
trap 'echo $( date ) Backup interrupted >> $log_file 2>&1; exit 2' INT TERM
info "Starting backup" >> $log_file 2>&1
# Backup the most important directories into an archive named after
# the machine this script is currently running on:
borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression zstd,1 \
--exclude-caches \
--exclude '/home/*/.cache/*' \
--exclude '/home/*/.local/share/Trash/*' \
--exclude '/home/pratik/Downloads/Videos/*' \
--exclude '/home/pratik/Downloads/Study/Video/*' \
--exclude '/var/cache/*' \
--exclude '/var/tmp/*' \
--exclude "$backup_dir" \
--exclude "$log_file" \
\
::"$unique_identifier-$backup_name-{now}" \
/etc \
/root \
/var \
>> $log_file 2>&1 \
backup_exit=$?
info "Pruning repository" >> $log_file 2>&1
# 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 \
--stats \
--prefix "$unique_identifier-$backup_name-" \
--show-rc \
--keep-within 2d \
--keep-last 5 \
--keep-daily 7 \
>> $log_file 2>&1 \
prune_exit=$?
# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
if [ ${global_exit} -eq 1 ];
then
info "Backup and/or Prune finished with a warning" >> $log_file 2>&1
fi
if [ ${global_exit} -gt 1 ];
then
info "Backup and/or Prune finished with an error" >> $log_file 2>&1
fi
exit ${global_exit}