Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backup and restore (closes #6) #8

Merged
merged 1 commit into from Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/config.js
Expand Up @@ -159,7 +159,7 @@ module.exports = {
// @type array
// @default ["sqlite", "text"]
//
messageStorage: ["sqlite", "text"],
messageStorage: ["sqlite"],

//
// Log settings
Expand Down
73 changes: 73 additions & 0 deletions scripts/backup
@@ -0,0 +1,73 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers

#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."

app=$YNH_APP_INSTANCE_NAME

final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)
domain=$(ynh_app_setting_get $app domain)

#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_print_info "Backing up the main app directory..."

ynh_backup "$final_path"

#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_print_info "Backing up nginx web server configuration..."

ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"

#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_print_info "Backing up logrotate configuration..."

ynh_backup "/etc/logrotate.d/$app"

#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_print_info "Backing up systemd configuration..."

ynh_backup "/etc/systemd/system/$app.service"

#=================================================
# BACKUP CONFIG
#=================================================
ynh_print_info "Backing up config path..."

ynh_backup "$config_path"

#=================================================
# END OF SCRIPT
#=================================================

ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
118 changes: 118 additions & 0 deletions scripts/restore
@@ -0,0 +1,118 @@

#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers

#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading settings..."

app=$YNH_APP_INSTANCE_NAME

domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
config_path=$(ynh_app_setting_get $app config_path)

#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_print_info "Validating restoration parameters..."

ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "

#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================

ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"

#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_print_info "Restoring the app main directory..."

ynh_restore_file "$final_path"

#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_print_info "Recreating the dedicated system user..."

# Create the dedicated user (if not existing)
ynh_system_user_create $app

#=================================================
# RESTORE USER RIGHTS
#=================================================

# Restore permissions to app files
chown -R $app: $final_path
chown -R $app: $config_path

#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info "Reinstalling dependencies..."

ynh_install_nodejs $nodejs_version

#=================================================
# RESTORE THE CONFIG
#=================================================
ynh_print_info "Restoring the config path..."

ynh_restore_file "$config_path"

#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_print_info "Restoring the systemd configuration..."

ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service

#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================

ynh_restore_file "/etc/logrotate.d/$app"

#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_print_info "Reloading nginx web server and The Lounge..."

systemctl restart thelounge
sleep 4
systemctl reload nginx

#=================================================
# END OF SCRIPT
#=================================================

ynh_print_info "Restoration completed for $app"