iotronic-lightning-rod/scripts/device_bkp_rest

54 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
echo "Option chosen: "$1
if [ "$1" = "backup" ]; then
if [ "$2" = "--path" ]; then
bkp_path=$3
else
bkp_path="."
fi
# BACKUP
echo "Backing up Iotronic configuration"
now_date=`date '+%Y%m%d%H%M%S'`
device=`cat /etc/iotronic/settings.json | grep name | awk '{print $2}' | tr -d \" | tr -d ,`
bkp_filename=$bkp_path"/bkp_"$device"_"$now_date".tar.gz"
echo "-> backup filename: " $bkp_filename
tar zcvf $bkp_filename /var/lib/iotronic /etc/iotronic /etc/letsencrypt /etc/nginx/conf.d &>/dev/null
elif [ "$1" = "restore" ]; then
if [ "$#" -ne 2 ]; then
echo "You have to specify: 'restore' <BACKUP_FILE_PATH> "
exit
fi
# RESTORE
echo "Restoring Iotronic configuration"
#tar -xvzf $2 -C /
tar -xvf $2 -C /
service nginx restart
sleep 3
echo -e "\nCompleted!"
else
echo "You have to specify:"
echo " - to backup: 'backup'"
echo " - options:"
echo " --path: specify path where to save the backup file; e.g.: /tmp or /home/<USER>"
echo ""
echo " - to restore: 'restore' <BACKUP_FILE_PATH>"
exit
fi