Compare commits
1 commit
2caa2302b5
...
0e985dc381
Author | SHA1 | Date | |
---|---|---|---|
|
0e985dc381 |
|
@ -27,59 +27,6 @@ while getopts ":f:h:u:p:m:b:" opt; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
TMP_FILENAME="duplicati_db-$(date +"%Y%m%d").bak"
|
|
||||||
TMP_FILEPATH="$SCRIPT_ABS_LOCATION"
|
|
||||||
|
|
||||||
log "Compressing and encrypting the Duplicati Databases"
|
|
||||||
sudo tar --absolute-names -czf - "$SOURCE_DIR" | openssl enc -aes-256-cbc -pbkdf2 -pass "pass:$BACKUP_ENCR_PASSPHRASE" > "$TMP_FILEPATH/$TMP_FILENAME" || {
|
|
||||||
log "Error: Failed to create encrypted archive."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
log "Fetching number of backups in destination folder"
|
|
||||||
EXISTING_BACKUPS=$(ssh -p 23 -i "$SSH_KEY" "$SSH_USERNAME@$SSH_DESTINATION" "ls '$BACKUP_FOLDER'" | wc -l) || {
|
|
||||||
log "Error: Failed to count existing backups."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if (( $EXISTING_BACKUPS > $MAX_BACKUPS )); then
|
|
||||||
log "Removing old backups in order to save space"
|
|
||||||
ssh "$SSH_USERNAME@$SSH_DESTINATION" -p 23 -i "$SSH_KEY" "ls -t $BACKUP_FOLDER | tail -n +$((MAX_BACKUPS+1)) | xargs rm" || { log "Error: Failed to remove old backups."; ex
|
|
||||||
it 1; }
|
|
||||||
fi
|
|
||||||
|
|
||||||
log "Transferring archive to SSH Destination"
|
|
||||||
scp -v -P 23 -i "$SSH_KEY" "$TMP_FILEPATH/$TMP_FILENAME" "$SSH_USERNAME@$SSH_DESTINATION:$BACKUP_FOLDER$TMP_FILENAME" || {
|
|
||||||
log "Error: Failed to transfer the encrypted archive."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
log "Cleaning up temporary files"
|
|
||||||
rm "$TMP_FILEPATH/$TMP_FILENAME" || {
|
|
||||||
log "Error: Failed to remove the temporary file."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
log "Backup completed successfully."
|
|
||||||
|
|
||||||
SOURCE_DIR="/mnt/data/duplicati"
|
|
||||||
|
|
||||||
# Set default values for parameters
|
|
||||||
MAX_BACKUPS=7
|
|
||||||
|
|
||||||
# Override default values with command-line arguments
|
|
||||||
while getopts ":f:h:u:p:m:b:" opt; do
|
|
||||||
case $opt in
|
|
||||||
f) SOURCE_DIR="$OPTARG";;
|
|
||||||
h) SSH_DESTINATION="$OPTARG";;
|
|
||||||
u) SSH_USERNAME="$OPTARG";;
|
|
||||||
p) SSH_KEY="$OPTARG";;
|
|
||||||
m) MAX_BACKUPS="$OPTARG";;
|
|
||||||
b) BACKUP_FOLDER="$OPTARG";;
|
|
||||||
\?) echo "Invalid option: -$OPTARG"; exit 1;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# Create a temporary file for the encrypted archive
|
# Create a temporary file for the encrypted archive
|
||||||
TMP_FILENAME="duplicati_db-$(date +"%Y%m%d").bak"
|
TMP_FILENAME="duplicati_db-$(date +"%Y%m%d").bak"
|
||||||
TMP_FILEPATH="$SCRIPT_ABS_LOCATION"
|
TMP_FILEPATH="$SCRIPT_ABS_LOCATION"
|
||||||
|
|
Loading…
Reference in a new issue