Last active
October 31, 2019 16:00
-
-
Save AlexBaranowski/64d96f009114ef5fe842cdcd66f0b238 to your computer and use it in GitHub Desktop.
Backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Author: Alex Baranowski | |
# This is trivial backup script | |
# Backup should be done on **different** physical disk, and as any other file can be moved &&|| replicated. | |
# Stop on the first error | |
set -e | |
[[ -v "$KEEP_DAYS" ]] || KEEP_DAYS=120 | |
[[ -v "$BACKUP_THIS" ]] || BACKUP_THIS="$HOME" | |
[[ -v "$BACKUP_TO" ]] || BACKUP_TO="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/backup" | |
echo "kD $KEEP_DAYS, BT: $BACKUP_THIS, BTO, $BACKUP_TO" | |
[ -d "$BACKUP_TO" ] || mkdir "$BACKUP_TO" | |
# create,verbose,permissions, gZip, file | |
ARGS="-cvpzf" | |
# Pigz cannot be used with z | |
hash pigz 2> /dev/null && ARGS="--use-compress-program=pigz -cvpf" | |
# In most cases .cache can be savely omited. | |
tar $ARGS "$BACKUP_TO/backup-$(date +%F).tar.gz" \ | |
--exclude="$BACKUP_THIS/.cache" \ | |
--exclude="$BACKUP_THIS/.local/share/Trash" \ | |
$BACKUP_THIS | |
echo -e "\n\nRemovingbackup older than $KEEP_DAYS\n\n" | |
find $BACKUP_TO -mtime +${KEEP_DAYS} -exec rm -v {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment