Skip to content

Commit

Permalink
nc-restore: try to detect old datadir in dataless restoration
Browse files Browse the repository at this point in the history
Signed-off-by: nachoparker <[email protected]>
  • Loading branch information
nachoparker committed Aug 17, 2021
1 parent 4f29d94 commit 35efcb6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
37 changes: 24 additions & 13 deletions bin/ncp/BACKUPS/nc-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ mysql -u root nextcloud < "$TMPDIR"/nextcloud-sqlbkp_*.bak || { echo "Error res
## RESTORE DATADIR
DATADIR=$( grep datadirectory "$NCDIR"/config/config.php | awk '{ print $3 }' | grep -oP "[^']*[^']" | head -1 )
[[ "$DATADIR" == "" ]] && { echo "Error reading data directory"; exit 1; }
cd "$NCDIR"
### INCLUDEDATA=yes situation
NUMFILES=2
if [[ $( ls "$TMPDIR" | wc -l ) -eq $NUMFILES ]]; then
DATADIR=$( grep datadirectory "$NCDIR"/config/config.php | awk '{ print $3 }' | grep -oP "[^']*[^']" | head -1 )
[[ "$DATADIR" == "" ]] && { echo "Error reading data directory"; exit 1; }
[[ -e "$DATADIR" ]] && {
echo "backing up existing $DATADIR to $DATADIR-$( date "+%m-%d-%y" )..."
mv "$DATADIR" "$DATADIR-$( date "+%m-%d-%y" )" || exit 1
Expand All @@ -115,21 +115,29 @@ if [[ $( ls "$TMPDIR" | wc -l ) -eq $NUMFILES ]]; then
rmdir "$DATADIR" || exit 1
btrfs subvolume create "$DATADIR" || exit 1
}
chown www-data:www-data "$DATADIR"
chown www-data: "$DATADIR"
TMPDATA="$TMPDIR/$( basename "$DATADIR" )"
mv "$TMPDATA"/* "$TMPDATA"/.[!.]* "$DATADIR" || exit 1
rmdir "$TMPDATA" || exit 1
sudo -u www-data php occ maintenance:mode --off
ncc maintenance:mode --off
### INCLUDEDATA=no situation
else
echo "no datadir found in backup"
DATADIR="$NCDIR"/data
echo "No datadir found in backup"
[[ -e "$DATADIR" ]] || {
echo "${DATADIR} not found. Resetting to ${NCDIR}/data"
DATADIR="$NCDIR"/data
mkdir -p "${DATADIR}"
touch "${DATADIR}"/.ocdata
chown www-data: "${DATADIR}"
sed -i "s|'datadirectory' =>.*|'datadirectory' => '${DATADIR}',|" "$NCDIR"/config/config.php
}
sudo -u www-data php occ maintenance:mode --off
sudo -u www-data php occ files:scan --all
ncc maintenance:mode --off
ncc files:scan --all
# cache needs to be cleaned as of NC 12
NEED_RESTART=1
Expand All @@ -140,12 +148,15 @@ sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$DATADIR/.opcache|" /etc/php
# tmp upload dir
mkdir -p "$DATADIR/tmp"
chown www-data:www-data "$DATADIR/tmp"
sudo -u www-data php occ config:system:set tempdirectory --value "$DATADIR/tmp"
chown www-data: "$DATADIR/tmp"
ncc config:system:set tempdirectory --value "$DATADIR/tmp"
sed -i "s|^;\?upload_tmp_dir =.*$|upload_tmp_dir = $DATADIR/tmp|" /etc/php/${PHPVER}/cli/php.ini
sed -i "s|^;\?upload_tmp_dir =.*$|upload_tmp_dir = $DATADIR/tmp|" /etc/php/${PHPVER}/fpm/php.ini
sed -i "s|^;\?sys_temp_dir =.*$|sys_temp_dir = $DATADIR/tmp|" /etc/php/${PHPVER}/fpm/php.ini
# logs
ncc config:system:set logfile --value="$DATADIR/nextcloud.log"
# update fail2ban logpath
[[ ! -f /.docker-image ]] && {
sed -i "s|logpath =.*|logpath = $DATADIR/nextcloud.log|" /etc/fail2ban/jail.conf
Expand All @@ -156,10 +167,10 @@ sed -i "s|^;\?sys_temp_dir =.*$|sys_temp_dir = $DATADIR/tmp|" /etc/php/${PHP
bash /usr/local/bin/nextcloud-domain.sh
# update the systems data-fingerprint
sudo -u www-data php occ maintenance:data-fingerprint
ncc maintenance:data-fingerprint
# refresh thumbnails
sudo -u www-data php occ files:scan-app-data
ncc files:scan-app-data
# restart PHP if needed
[[ "$NEED_RESTART" == "1" ]] && \
Expand Down
12 changes: 6 additions & 6 deletions bin/ncp/CONFIG/nc-datadir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ configure()

## CHECKS
local SRCDIR
SRCDIR=$( cd /var/www/nextcloud; sudo -u www-data php occ config:system:get datadirectory ) || {
SRCDIR=$( cd /var/www/nextcloud; ncc config:system:get datadirectory ) || {
echo -e "Error reading data directory. Is NextCloud running and configured?";
return 1;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ configure()

## COPY
cd /var/www/nextcloud
sudo -u www-data php occ maintenance:mode --on
ncc maintenance:mode --on

echo "moving data directory from $SRCDIR to $DATADIR..."

Expand All @@ -86,7 +86,7 @@ configure()
# tmp upload dir
mkdir -p "$DATADIR/tmp"
chown www-data:www-data "$DATADIR/tmp"
sudo -u www-data php occ config:system:set tempdirectory --value "$DATADIR/tmp"
ncc config:system:set tempdirectory --value "$DATADIR/tmp"
sed -i "s|^;\?upload_tmp_dir =.*$|uploadtmp_dir = $DATADIR/tmp|" /etc/php/${PHPVER}/cli/php.ini
sed -i "s|^;\?upload_tmp_dir =.*$|upload_tmp_dir = $DATADIR/tmp|" /etc/php/${PHPVER}/fpm/php.ini
sed -i "s|^;\?sys_temp_dir =.*$|sys_temp_dir = $DATADIR/tmp|" /etc/php/${PHPVER}/fpm/php.ini
Expand All @@ -99,9 +99,9 @@ configure()
sed -i "s|logpath =.*nextcloud.log|logpath = $DATADIR/nextcloud.log|" /etc/fail2ban/jail.local

# datadir
sudo -u www-data php occ config:system:set datadirectory --value="$DATADIR"
sudo -u www-data php occ config:system:set logfile --value="$DATADIR/nextcloud.log"
sudo -u www-data php occ maintenance:mode --off
ncc config:system:set datadirectory --value="$DATADIR"
ncc config:system:set logfile --value="$DATADIR/nextcloud.log"
ncc maintenance:mode --off
}

# License
Expand Down
8 changes: 6 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

[v1.38.0](https://github.com/nextcloud/nextcloudpi/commit/d5f50a1) (2021-08-09) upgrade to NC20.0.12
[v1.38.2](https://github.com/nextcloud/nextcloudpi/commit/82e4e72) (2021-08-16) nc-restore: try to detect old datadir in dataless restoration

[v1.37.9](https://github.com/nextcloud/nextcloudpi/commit/b8c1409) (2021-08-09) letsencrypt: ability to disable it and roll back to self-signed certificates
[v1.38.1 ](https://github.com/nextcloud/nextcloudpi/commit/4f29d94) (2021-08-16) nextcloud.conf.sh: Prevent apache config test output to end up in generated template

[v1.38.0](https://github.com/nextcloud/nextcloudpi/commit/6e2dca5) (2021-08-09) upgrade to NC20.0.12

[v1.37.9 ](https://github.com/nextcloud/nextcloudpi/commit/b8c1409) (2021-08-09) letsencrypt: ability to disable it and roll back to self-signed certificates

[v1.37.8 ](https://github.com/nextcloud/nextcloudpi/commit/5a05b89) (2021-08-08) nextcloud: remove beta option

Expand Down
4 changes: 2 additions & 2 deletions etc/ncp-config.d/nc-backup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"id": "nc-backup",
"name": "nc-backup",
"title": "nc-backup",
"description": "Backup this NC instance to a file. This will always include the current Nextcloud directory and the Database. You can choose to include or exclude NC-data.",
"info": "",
"description": "Backup this NC instance to a file",
"info": "This will always include the current Nextcloud directory and the Database.\nYou can choose to include or exclude NC-data.",
"infotitle": "",
"params": [
{
Expand Down
2 changes: 2 additions & 0 deletions updates/1.38.0.sh → updates/1.39.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ echo "*/5 * * * * php -f /var/www/nextcloud/cron.php" > "${crontab_tmp}"
crontab -u www-data "${crontab_tmp}"
rm "${crontab_tmp}"

## update nc-restore
install_app nc-restore

# docker images only
[[ -f /.docker-image ]] && {
Expand Down

0 comments on commit 35efcb6

Please sign in to comment.