Skip to content

Commit

Permalink
Backup and data restoration
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed May 28, 2021
1 parent 4645de7 commit 6fc5b0f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
9 changes: 9 additions & 0 deletions createlinks
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ event_actions("nethserver-nextcloud-save", qw(
event_actions("interface-update", qw(
nethserver-nextcloud-occ-conf 91
));

# link to backup and restore event
event_actions("pre-backup-data", qw(
nethserver-nextcloud-rh-mariadb105-dump-database 60
));

event_actions("post-restore-data", qw(
nethserver-nextcloud-restore-rh-mariadb105-database 03
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
#
# Copyright (C) 2021 Nethesis S.r.l.
# http://www.nethesis.it - [email protected]
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NethServer. If not, see <http://www.gnu.org/licenses/>.
#

source /opt/rh/rh-mariadb105/enable
PATH=$PATH:/opt/rh/rh-mariadb105/root/usr/bin/

umask 0027
backup_dir=/var/lib/nethserver/backup/rh-mariadb105/

if [ ! -d $backup_dir ]; then
mkdir -p $backup_dir
fi

mysqldump --socket /run/rh-mariadb105-mariadb/nextcloud-mysql.sock \
--databases nextcloud --default-character-set=utf8mb4 \
--skip-dump-date --ignore-table=mysql.event --single-transaction \
--quick --add-drop-table \
-r $backup_dir/nextcloud.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
#
# Copyright (C) 2021 Nethesis S.r.l.
# http://www.nethesis.it - [email protected]
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NethServer. If not, see <http://www.gnu.org/licenses/>.
#

source /opt/rh/rh-mariadb105/enable
PATH=$PATH:/opt/rh/rh-mariadb105/root/usr/bin/

if [[ ! -f '/var/lib/nethserver/backup/rh-mariadb105/nextcloud.sql' ]]; then
echo "[ERROR] Error the nextcloud SCL mariadb105 dump does not exist"
exit 1
fi

password=`perl -e "use NethServer::Password; print NethServer::Password::store('nextcloud');"`
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "CREATE DATABASE IF NOT EXISTS nextcloud;"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock --database nextcloud < /var/lib/nethserver/backup/rh-mariadb105/nextcloud.sql
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "ALTER DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "grant all on nextcloud.* to 'nextcloud'@'localhost' identified by '$password';"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "FLUSH PRIVILEGES"

if [[ $? -ne 0 ]]; then
echo "[ERROR] Error while restoring nextcloud database to SCL mariadb105"
exit 1
fi

rm -f /var/lib/nethserver/backup/rh-mariadb105/nextcloud.sql

0 comments on commit 6fc5b0f

Please sign in to comment.