From 9d68f09bfc080cff09c12bb40dfff13cde55ddf0 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Fri, 20 Oct 2017 13:09:26 +0200 Subject: [PATCH] Add backup and restore scripts --- scripts/backup | 61 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 2 +- scripts/restore | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ scripts/upgrade | 0 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100755 scripts/backup create mode 100755 scripts/restore mode change 100644 => 100755 scripts/upgrade diff --git a/scripts/backup b/scripts/backup new file mode 100755 index 0000000..d6db608 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,61 @@ +#!/bin/bash +# Exit on command errors and treat unset variables as an error +set -eu + +#================================================= +# GENERIC STARTING +#================================================= + +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the functions file if not present in the current directory + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +pvp=$(ynh_app_setting_get $app pvp) +damage=$(ynh_app_setting_get $app damage) +domain=$(ynh_app_setting_get $app domain) +creative=$(ynh_app_setting_get $app creative) +is_public=$(ynh_app_setting_get $app is_public) + +#================================================= +# BACKUP STEPS +#================================================= +# CONFIGURATION +#================================================= +CHECK_SIZE "/etc/minetest.conf" +ynh_backup "/etc/minetest.conf" + +#================================================= +# DATA +#================================================= +CHECK_SIZE "/var/games/minetest-server/" +ynh_backup "/var/games/minetest-server/" + +echo ".backup /tmp/map.sqlite" | sqlite3 /var/games/minetest-server/.minetest/worlds/world +CHECK_SIZE "/tmp/map.sqlite" +ynh_backup "/tmp/map.sqlite" +ynh_secure_remove "/tmp/map.sqlite" + +#================================================= +# BACKUP OF APT PREFERENCES AND SOURCES.LIST +#================================================= +CHECK_SIZE "/etc/apt/sources.list.d/$app.list" +ynh_backup "/etc/apt/sources.list.d/$app.list" + +CHECK_SIZE "/etc/apt/preferences.d/00MinetestPinning" +ynh_backup "/etc/apt/preferences.d/00MinetestPinning" + + diff --git a/scripts/install b/scripts/install index dcdea83..5f4aada 100755 --- a/scripts/install +++ b/scripts/install @@ -86,7 +86,7 @@ then fi fi ynh_package_update -ynh_install_app_dependencies minetest-server +ynh_install_app_dependencies minetest-server sqlite3 #================================================= # ENABLE SERVICE IN ADMIN PANEL diff --git a/scripts/restore b/scripts/restore new file mode 100755 index 0000000..092f717 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,63 @@ +#!/bin/bash +# Exit on command errors and treat unset variables as an error +set -eu + +#================================================= +# GENERIC STARTING +#================================================= + +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +if [ ! -e _common.sh ]; then + # Get the functions file if not present in the current directory + sudo cp ../settings/scripts/_common.sh ./_common.sh + sudo chmod a+rx _common.sh +fi +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +pvp=$(ynh_app_setting_get $app pvp) +damage=$(ynh_app_setting_get $app damage) +domain=$(ynh_app_setting_get $app domain) +creative=$(ynh_app_setting_get $app creative) +is_public=$(ynh_app_setting_get $app is_public) + +#================================================= +# BACKUP STEPS +#================================================= +# STOP SERVICE +#================================================= +service minetest stop + +#================================================= +# CONFIGURATION +#================================================= +ynh_restore_file "/etc/minetest.conf" + +#================================================= +# DATA +#================================================= +ynh_restore_file "/var/games/minetest-server/" + +ynh_restore_file "/tmp/map.sqlite" +echo ".restore /tmp/map.sqlite" | sqlite3 /var/games/minetest-server/.minetest/worlds/world + +#================================================= +# BACKUP OF APT PREFERENCES AND SOURCES.LIST +#================================================= +ynh_restore_file "/etc/apt/sources.list.d/$app.list" + +ynh_restore_file "/etc/apt/preferences.d/00MinetestPinning" + +#================================================= +# START SERVICE +#================================================= +service minetest start diff --git a/scripts/upgrade b/scripts/upgrade old mode 100644 new mode 100755