Skip to content

Commit 03e9682

Browse files
committed
nc-restore: fix tmp dirs in backups without data
1 parent 98d34a4 commit 03e9682

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

etc/ncp-config.d/nc-restore.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ install()
3131
{
3232
cat > /usr/local/bin/ncp-restore <<'EOF'
3333
#!/bin/bash
34-
set -e
34+
set -eE
3535
3636
BACKUPFILE="$1"
3737
@@ -42,9 +42,10 @@ DBPASSWD="$( grep password /root/.my.cnf | sed 's|password=||' )"
4242
[ -f "$BACKUPFILE" ] || { echo "$BACKUPFILE not found" ; exit 1; }
4343
[ -d /var/www/nextcloud ] && { echo "INFO: overwriting old instance"; }
4444
45-
TMPDIR="$( mktemp -d "$( dirname $BACKUPFILE )"/ncp-restore.XXXXXX )" || { echo "Failed to create temp dir" >&2; exit 1; }
46-
cleanup(){ local RET=$?; echo "Cleanup..."; rm -rf "${TMPDIR}"; exit $RET; }
47-
trap cleanup INT TERM HUP EXIT
45+
TMPDIR="$( mktemp -d "$( dirname "$BACKUPFILE" )"/ncp-restore.XXXXXX )" || { echo "Failed to create temp dir" >&2; exit 1; }
46+
TMPDIR="$( cd "$TMPDIR" &>/dev/null && pwd )" || { echo "$TMPDIR not found"; exit 1; } #abspath
47+
cleanup(){ local RET=$?; echo "Cleanup..."; rm -rf "${TMPDIR}"; trap "" EXIT; exit $RET; }
48+
trap cleanup INT TERM HUP ERR EXIT
4849
rm -rf "$TMPDIR" && mkdir -p "$TMPDIR"
4950
5051
# EXTRACT FILES
@@ -136,28 +137,35 @@ else
136137
sudo -u www-data php occ maintenance:mode --off
137138
sudo -u www-data php occ files:scan --all
138139
139-
# Just in case we moved the opcache dir
140-
sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$DATADIR/.opcache|" /etc/php/7.0/mods-available/opcache.ini
141-
142140
# cache needs to be cleaned as of NC 12
143-
bash -c " sleep 3
144-
systemctl stop php7.0-fpm
145-
systemctl stop mysqld
146-
sleep 0.5
147-
systemctl start php7.0-fpm
148-
systemctl start mysqld
149-
" &>/dev/null &
141+
NEED_RESTART=1
150142
fi
151143
152144
# Just in case we moved the opcache dir
153145
sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$DATADIR/.opcache|" /etc/php/7.0/mods-available/opcache.ini
154146
147+
# tmp upload dir
148+
mkdir -p "$DATADIR/tmp"
149+
chown www-data:www-data "$DATADIR/tmp"
150+
sed -i "s|^;\?upload_tmp_dir =.*$|upload_tmp_dir = $DATADIR/tmp|" /etc/php/7.0/fpm/php.ini
151+
sed -i "s|^;\?sys_temp_dir =.*$|sys_temp_dir = $DATADIR/tmp|" /etc/php/7.0/fpm/php.ini
152+
155153
# update fail2ban logpath
156154
sed -i "s|logpath =.*|logpath = $DATADIR/nextcloud.log|" /etc/fail2ban/jail.conf
157155
pgrep fail2ban &>/dev/null && service fail2ban restart
158156
159157
# refresh nextcloud trusted domains
160158
bash /usr/local/bin/nextcloud-domain.sh
159+
160+
# restart PHP if needed
161+
[[ "$NEED_RESTART" == "1" ]] && \
162+
bash -c " sleep 3
163+
systemctl stop php7.0-fpm
164+
systemctl stop mysqld
165+
sleep 0.5
166+
systemctl start php7.0-fpm
167+
systemctl start mysqld
168+
" &>/dev/null &
161169
EOF
162170
chmod +x /usr/local/bin/ncp-restore
163171
}

0 commit comments

Comments
 (0)