seafile_ynh/scripts/backup
2017-01-05 23:24:32 +01:00

45 lines
No EOL
1.3 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Import common cmd
source ./_common.sh
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
# Set configuration for user and final path
set_configuration
# 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=$(ynh_app_setting_get ${APP} domain)
db_pwd=$(ynh_app_setting_get ${APP} db_pwd)
# Backup app files
sudo mkdir -p "${BACKUP_DIR}/www"
sudo cp -a $final_path/. "${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/${APP} "${BACKUP_DIR}/conf/${APP}"
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
mysqldump -u ${APP} -p$db_pwd ccnetdb | sudo dd of=${BACKUP_DIR}/ccnetdb.dmp
mysqldump -u ${APP} -p$db_pwd seafiledb | sudo dd of=${BACKUP_DIR}/seafiledb.dmp
mysqldump -u ${APP} -p$db_pwd seahubdb | sudo dd of=${BACKUP_DIR}/seahubdb.dmp