From f63a353bcd82b6c539fb15e86459662b7a84ab11 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Fri, 5 Jan 2018 18:41:06 +0100 Subject: nc-restore: restore compressed backups --- etc/nextcloudpi-config.d/nc-restore.sh | 88 ++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 41 deletions(-) (limited to 'etc') diff --git a/etc/nextcloudpi-config.d/nc-restore.sh b/etc/nextcloudpi-config.d/nc-restore.sh index 7e3fee31..fc2033d7 100644 --- a/etc/nextcloudpi-config.d/nc-restore.sh +++ b/etc/nextcloudpi-config.d/nc-restore.sh @@ -17,7 +17,6 @@ BACKUPFILE_=/media/USBdrive/nextcloud-bkp_xxxxxxxx.tar -BASEDIR=/var/www DBADMIN=ncadmin DESCRIPTION="Restore a previously backuped NC instance" @@ -33,28 +32,41 @@ configure() { local DBPASSWD=$( grep password /root/.my.cnf | cut -d= -f2 ) - [ -f $BACKUPFILE_ ] || { echo -e "$BACKUPFILE_ not found"; return 1; } - [ -d $BASEDIR ] || { echo -e "$BASEDIR not found"; return 1; } - [ -d $BASEDIR/nextcloud ] && { echo -e "INFO: overwriting old instance"; } + [ -f $BACKUPFILE_ ] || { echo "$BACKUPFILE_ not found"; return 1; } + [ -d /var/www/nextcloud ] && { echo "INFO: overwriting old instance" ; } local TMPDIR="$( dirname $BACKUPFILE_ )/$( basename ${BACKUPFILE_}-tmp )" rm -rf "$TMPDIR" && mkdir -p "$TMPDIR" - echo -e "extracting backup file $BACKUPFILE_..." + # EXTRACT FILES + [[ "$BACKUPFILE_" =~ ".tar.gz" ]] && { + echo "decompressing backup file $BACKUPFILE_..." + tar -xzf "$BACKUPFILE_" -C "$TMPDIR" || return 1 + BACKUPFILE_="$( ls "$TMPDIR"/*.tar 2>/dev/null )" + [[ -f "$BACKUPFILE_" ]] || { echo "$BACKUPFILE_ not found"; return 1; } + } + + echo "extracting backup file $BACKUPFILE_..." tar -xf "$BACKUPFILE_" -C "$TMPDIR" || return 1 ## RESTORE FILES - echo -e "restore files..." - rm -rf $BASEDIR/nextcloud - mv "$TMPDIR"/nextcloud $BASEDIR || { echo -e "Error restoring base files"; return 1; } + echo "restore files..." + rm -rf /var/www/nextcloud + mv "$TMPDIR"/nextcloud /var/www || { echo "Error restoring base files"; return 1; } # update NC database password to this instance - sed -i "s|'dbpassword' =>.*|'dbpassword' => '$DBPASSWD',|" $BASEDIR/nextcloud/config/config.php + sed -i "s|'dbpassword' =>.*|'dbpassword' => '$DBPASSWD',|" /var/www/nextcloud/config/config.php + + # update redis credentials + local REDISPASS="$( grep "^requirepass" /etc/redis/redis.conf | cut -f2 -d' ' )" + [[ "$REDISPASS" != "" ]] && \ + sed -i "s|'password'.*|'password' => '$REDISPASS',|" /var/www/nextcloud/config/config.php + service redis restart ## RE-CREATE DATABASE TABLE - echo -e "restore database..." + echo "restore database..." mysql -u root <.*|'datadirectory' => '/var/www/nextcloud/data',|" config/config.php - - # Just in case we moved the opcache dir - sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$BASEDIR/nextcloud/data/.opcache|" /etc/php/7.0/mods-available/opcache.ini - - # update fail2ban logpath - sed -i "s|logpath =.*|logpath = /var/www/nextcloud/data/nextcloud.log|" /etc/fail2ban/jail.conf - - # update redis credentials - local REDISPASS="$( grep "^requirepass" /etc/redis/redis.conf | cut -f2 -d' ' )" - [[ "$REDISPASS" != "" ]] && \ - sed -i "s|'password'.*|'password' => '$REDISPASS',|" config/config.php + echo "no datadir found in backup" + local DATADIR=/var/www/nextcloud/data sudo -u www-data php occ maintenance:mode --off sudo -u www-data php occ files:scan --all + # Just in case we moved the opcache dir + sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$DATADIR/.opcache|" /etc/php/7.0/mods-available/opcache.ini + # cache needs to be cleaned as of NC 12 - bash -c " sleep 3 systemctl stop php7.0-fpm systemctl stop mysqld @@ -124,7 +125,12 @@ EOF " &>/dev/null & fi - service fail2ban restart + # Just in case we moved the opcache dir + sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$DATADIR/.opcache|" /etc/php/7.0/mods-available/opcache.ini + + # update fail2ban logpath + sed -i "s|logpath =.*|logpath = $DATADIR/nextcloud.log|" /etc/fail2ban/jail.conf + pgrep fail2ban &>/dev/null && service fail2ban restart rm -r "$TMPDIR" } -- cgit v1.2.3