Bootstrap backup/restore script

Former-commit-id: 7298080dcb
This commit is contained in:
mbugeia 2015-12-26 14:14:31 +01:00
parent b2fe60baaa
commit 0d9551d8c0
2 changed files with 88 additions and 0 deletions

32
scripts/backup Normal file
View file

@ -0,0 +1,32 @@
#!/bin/bash
set -e
# The parameter $1 is the backup directory location dedicated to the app
BACKUP_DIR=$1
# The parameter $2 is the id of the app instance ex: strut__2
app=$2
# retrieve useful param
domain=$(sudo yunohost app setting $app domain)
db_pwd=$(sudo yunohost app setting $app mysqlpwd)
# Backup app files
sudo mkdir -p "${BACKUP_DIR}/www"
sudo cp -a /var/www/$app/. "${BACKUP_DIR}/www"
# Backup conf files
sudo mkdir -p "${BACKUP_DIR}/conf"
sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf "${BACKUP_DIR}/conf/${app}.conf"
sudo cp -a /etc/logrotate.d/seafile "${BACKUP_DIR}/conf/seafile"
sudo cp -a /etc/init.d/seafile-server "${BACKUP_DIR}/conf/seafile-server"
# Backup data
sudo mkdir -p "${BACKUP_DIR}/data"
sudo cp -a /home/yunohost.app/seafile-data/. "${BACKUP_DIR}/data"
# Backup mysql
sudo mysqldump -u $app -p$db_pwd ccnetdb > "${BACKUP_DIR}/ccnetdb.dmp"
sudo mysqldump -u $app -p$db_pwd seafiledb > "${BACKUP_DIR}/seafiledb.dmp"
sudo mysqldump -u $app -p$db_pwd seahubdb > "${BACKUP_DIR}/seahubdb.dmp"

56
scripts/restore Normal file
View file

@ -0,0 +1,56 @@
#!/bin/bash
set -e
# The parameter $1 is the backup directory location dedicated to the app
BACKUP_DIR=$1
# The parameter $2 is the id of the app instance ex: strut__2
app=$2
domain=$(sudo yunohost app setting $app domain)
path=$(sudo yunohost app setting $app path)
db_pwd=$(sudo yunohost app setting $app mysqlpwd)
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app \
|| (echo "Path not available: $domain$path" && exit 1)
# Restore dependencies
sudo apt-get update
sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect
# Restore app files
final_path=/var/www/$app
sudo mkdir -p $final_path
sudo cp -a "${BACKUP_DIR}/www/." $final_path
sudo chown -R www-data:www-data $final_path
# Restore conf files
sudo cp -a "${BACKUP_DIR}/conf/${app}.conf" /etc/nginx/conf.d/$domain.d/$app.conf
sudo cp -a "${BACKUP_DIR}/conf/seafile" /etc/logrotate.d/seafile
sudo cp -a "${BACKUP_DIR}/conf/seafile-server" /etc/init.d/seafile-server
sudo chmod +x /etc/init.d/seafile-server
# Restore data
seafile_data=/home/yunohost.app/seafile-data
mkdir -p $seafile_data
sudo cp -a "${BACKUP_DIR}/data/." /home/yunohost.app/seafile-data/.
sudo chown -R www-data:www-data $seafile_data
# Restore mysql dump
sudo mysql -u $app -p$db_pwd ccnetdb < "${BACKUP_DIR}/ccnetdb.dmp"
sudo mysql -u $app -p$db_pwd seafiledb < "${BACKUP_DIR}/seafiledb.dmp"
sudo mysql -u $app -p$db_pwd seahubdb < "${BACKUP_DIR}/seahubdb.dmp"
# Add Seafile to YunoHost's monitored services
sudo yunohost service add seafile-server
# Reload/restart services
sudo update-rc.d seafile-server defaults
sudo service rsyslog restart
sudo service nginx reload
sudo yunohost app ssowatconf
# start seafile
sudo service seafile-server start