Last active
January 26, 2020 19:40
-
-
Save SIRprise/a5cdbac73a95536cd3fee1ce06c81aa8 to your computer and use it in GitHub Desktop.
Backup script for uberspace
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 | |
### Uberspace Backup-Script by SIRprise | |
## merge of | |
## https://www.gehaxelt.in/blog/ueberspace-backupscript/ | |
## and | |
## https://sebastian-doering.net/linux/vollstaendiges-uberspace-backup/ | |
## because the first one does not backup home and the second creates an empty www folder | |
## Version 0.9 | |
## --------------------------- | |
## This is the first script: | |
## Variables | |
#USER='MyUsername' #Uberspacename <- should be already set in $USER by environment | |
DATE=$(date +%Y-%m-%d-%H%M%S) #Current time | |
BACKUP_DIR="$HOME/Backup" | |
## END Variables | |
##Check if backup folder exists and create it | |
if [ ! -d $BACKUP_DIR ] | |
then | |
mkdir $BACKUP_DIR | |
echo "Backup-folder created" | |
fi | |
##END Check | |
##Check if backup file exists and exit | |
if [ -f $BACKUP_DIR/backup-$DATE.tar.bz2 ] | |
then | |
echo "Backup already exists" | |
exit 1 | |
fi | |
##END Check | |
##Backup | |
##mysqldump --defaults-file=$HOME/.my.cnf --user=$USER --compact --comments --dump-date --quick --all-databases | gzip > "/var/www/virtual/"$USER"/database.sql.gz" | |
mysqldump --defaults-file=$HOME/.my.cnf --user=$USER --compact --comments --dump-date --quick --all-databases | gzip > "$BACKUP_DIR/MySQL_Backup.sql" | |
##cd /var/www/virtual/$USER | |
##tar -cjf $BACKUP_DIR/www-backup-$DATE.tar.bz2 /var/www/virtual/$USER | |
cd /home/$USER | |
tar -cjf $BACKUP_DIR/backup-$DATE.tar.bz2 --exclude='backup*.tar.bz2' /var/www/virtual/$USER . * | |
##rm /var/www/virtual/$USER/database.sql.gz | |
rm "$BACKUP_DIR/MySQL_Backup.sql" | |
##END Backup | |
## --------------------------- | |
##SOURCE="$HOME /var/www/virtual/$USER/html" | |
##mysqldump --all-databases > $BACKUP_DIR/MySQL_Backup.sql | |
## tar -cjpf $BACKUP_DIR/Backup.tar.bz2 $SOURCE --exclude="$BACKUP_DIR" --exclude="$HOME/tmp" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment