Created
September 17, 2016 16:10
-
-
Save NxSoftware/f32b643ae8b1ac016a1d48cc5cd8a8a1 to your computer and use it in GitHub Desktop.
Domoticz 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
#!/bin/bash | |
BACKUP_SERVER=mac-mini-server.local | |
BACKUP_PORT=2222 | |
BACKUP_USERNAME=domoticz | |
DOMOTICZ_SERVER=127.0.0.1 | |
DOMOTICZ_PORT=8080 | |
DOMOTICZ_DIR="/home/pi/domoticz" | |
DOMOTICZ_WWW_DIR="$DOMOTICZ_DIR/www" | |
DOMOTICZ_SCRIPTS_DIR="$DOMOTICZ_DIR/scripts" | |
TIMESTAMP=`/bin/date +%Y%m%d%H%M%S` | |
BACKUPROOT="/tmp/domoticz_backup" | |
BACKUPDIR="$BACKUPROOT/$TIMESTAMP" | |
FILE_DB="domoticz.db" | |
FILE_WWW="www" | |
FILE_SCRIPTS="scripts" | |
BACKUP_DB="${BACKUPDIR}/$FILE_DB" | |
BACKUP_WWW="${BACKUPDIR}/$FILE_WWW" | |
BACKUP_SCRIPTS="${BACKUPDIR}/$FILE_SCRIPTS" | |
ARCHIVE="domoticz_$TIMESTAMP.gz" | |
# Create the directory if it does not exist | |
mkdir -p $BACKUPDIR | |
cd $BACKUPDIR | |
# Copy various components | |
# Database | |
echo 'Backing up database...' | |
curl -s "http://$DOMOTICZ_SERVER:$DOMOTICZ_PORT/backupdatabase.php" > $BACKUP_DB | |
# WWW | |
echo 'Backing up ./www' | |
cp -r $DOMOTICZ_WWW_DIR $BACKUP_WWW | |
# Scripts | |
echo 'Backing up ./scripts' | |
cp -r $DOMOTICZ_SCRIPTS_DIR $BACKUP_SCRIPTS | |
# Compress | |
echo 'Compressing archive...' | |
tar -czvf $ARCHIVE $FILE_DB $FILE_WWW $FILE_SCRIPTS | |
# Send to server | |
echo 'Uploading...' | |
scp -P $BACKUP_PORT $ARCHIVE $BACKUP_USERNAME@$BACKUP_SERVER:$ARCHIVE | |
# Remove local backups | |
echo 'Removing local backups...' | |
rm -rf $BACKUPDIR | |
echo 'Done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment