Last active
February 5, 2021 08:51
-
-
Save phimuemue/1ebc7e3c33aadb4164fedc6fe07913f5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/bash | |
| # see https://stackoverflow.com/questions/59895 | |
| SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
| BACKUP_ROOT=$SCRIPTDIR/backup | |
| BACKUP_ROOT_USER=$BACKUP_ROOT/$USER | |
| mkdir -p $BACKUP_ROOT_USER | |
| BACKUP_ERROR_FILE=$BACKUP_ROOT_USER/error.log | |
| function handle_error { | |
| if [[ $? -eq 0 ]] | |
| then | |
| echo "Backup erstellt"; | |
| else | |
| SCRIPTERRCODE=$?; | |
| echo "Fehler => Siehe" $BACKUP_ERROR_FILE; | |
| read -n1; | |
| exit $SCRIPTERRCODE | |
| fi | |
| } | |
| function backup { | |
| DATE=`date +%Y_%m_%d_%H_%M_%S` | |
| echo "Erstelle Backup fuer Nutzer" $USER "mit Datum" $DATE | |
| SRC_FOLDER=$HOME | |
| echo "Quelle:" $SRC_FOLDER | |
| EXCLUDE_BACKUP_FOLDER=`realpath --relative-to=$SRC_FOLDER $BACKUP_ROOT` | |
| BACKUP_ROOT_USER_CHRONO=$BACKUP_ROOT_USER/chronologisch | |
| DST_FOLDER_DIFFERENTIAL=$BACKUP_ROOT_USER_CHRONO/$DATE | |
| echo "Ziel chronologisch:" $DST_FOLDER_DIFFERENTIAL | |
| mkdir -p $BACKUP_ROOT_USER_CHRONO/1900 # hack to have an "initial empty backup" | |
| DST_FOLDER_DIFFERENTIAL_OLD=`ls $BACKUP_ROOT_USER_CHRONO | sort | tail -n1` | |
| mkdir -p $DST_FOLDER_DIFFERENTIAL | |
| RSYNC_LOG_FILE=$BACKUP_ROOT_USER/backup_rsync.log | |
| rsync -avP --log-file=$RSYNC_LOG_FILE --link-dest $BACKUP_ROOT_USER_CHRONO/$DST_FOLDER_DIFFERENTIAL_OLD --exclude $EXCLUDE_BACKUP_FOLDER $SRC_FOLDER/ $DST_FOLDER_DIFFERENTIAL/ | |
| handle_error | |
| BACKUP_ROOT_USER_ACCU=$BACKUP_ROOT_USER/akkumuliert | |
| echo "Ziel akkumuliert:" $BACKUP_ROOT_USER_ACCU | |
| mkdir -p $BACKUP_ROOT_USER_ACCU | |
| rsync -avP --log-file=$RSYNC_LOG_FILE --link-dest $DST_FOLDER_DIFFERENTIAL --exclude $EXCLUDE_BACKUP_FOLDER $SRC_FOLDER/ $BACKUP_ROOT_USER_ACCU/ | |
| handle_error | |
| } | |
| backup 2>$BACKUP_ERROR_FILE | tee -a $BACKUP_ROOT_USER/backup.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment