From d7283bd57a0adba1ffb1bbeca27661901053fcbc Mon Sep 17 00:00:00 2001 From: DecaTec Date: Mon, 24 Dec 2018 15:36:09 +0100 Subject: [PATCH] Added support for PostgreSQL; Restore MySQL with UTF8 support --- NextcloudBackup.sh | 4 ++++ NextcloudRestore.sh | 17 ++++++++++++++++- README.md | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/NextcloudBackup.sh b/NextcloudBackup.sh index fb20a47..3e08cb4 100644 --- a/NextcloudBackup.sh +++ b/NextcloudBackup.sh @@ -123,7 +123,11 @@ echo # Backup DB # echo "Backup Nextcloud database..." +# MySQL/MariaDB: mysqldump --single-transaction -h localhost -u "${dbUser}" -p"${dbPassword}" "${nextcloudDatabase}" > "${backupdir}/${fileNameBackupDb}" + +# PostgreSQL (uncomment if you are using PostgreSQL as Nextcloud database) +#PGPASSWORD="${dbPassword}" pg_dump "${nextcloudDatabase}" -h localhost -U "${dbUser}" -f "${backupdir}/${fileNameBackupDb}" echo "Done" echo diff --git a/NextcloudRestore.sh b/NextcloudRestore.sh index b64d758..e57b998 100644 --- a/NextcloudRestore.sh +++ b/NextcloudRestore.sh @@ -121,17 +121,32 @@ echo # Restore database # echo "Dropping old Nextcloud DB..." +# MySQL/MariaDB: mysql -h localhost -u "${dbUser}" -p"${dbPassword}" -e "DROP DATABASE ${nextcloudDatabase}" + +# PostgreSQL (uncomment if you are using PostgreSQL as Nextcloud database) +#PGPASSWORD="${dbPassword} psql -h localhost -U "${dbUser}" -d nextcloud -c "DROP DATABASE \"${nextcloudDatabase}\";" echo "Done" echo echo "Creating new DB for Nextcloud..." -mysql -h localhost -u "${dbUser}" -p"${dbPassword}" -e "CREATE DATABASE ${nextcloudDatabase}" +# MySQL/MariaDB: +# Use this if the databse from the backup uses UTF8 with multibyte support (e.g. for emoijs in filenames): +mysql -h localhost -u "${dbUser}" -p"${dbPassword}" -e "CREATE DATABASE ${nextcloudDatabase} CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" +# Use this if the database from the backup DOES NOT use UTF8 with multibyte support (e.g. for emoijs in filenames): +#mysql -h localhost -u "${dbUser}" -p"${dbPassword}" -e "CREATE DATABASE ${nextcloudDatabase}" + +# PostgreSQL (uncomment if you are using PostgreSQL as Nextcloud database) +#PGPASSWORD="${dbPassword}" psql -h localhost -U "${dbUser}" -d "${nextcloudDatabase}" -c "CREATE DATABASE \"${nextcloudDatabase}\";" echo "Done" echo echo "Restoring backup DB..." +# MySQL/MariaDB: mysql -h localhost -u "${dbUser}" -p"${dbPassword}" "${nextcloudDatabase}" < "${currentRestoreDir}/${fileNameBackupDb}" + +# PostgreSQL (uncomment if you are using PostgreSQL as Nextcloud database) +#PGPASSWORD="${dbPassword}" pg_restore -c -d "${nextcloudDatabase}" -h localhost -U "${dbUser}" "${currentRestoreDir}/${fileNameBackupDb}" echo "Done" echo diff --git a/README.md b/README.md index d489288..8849dd7 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ The scripts take care of these three items to backup automatically. - The scripts assume that Nextcloud's data directory is *not* a subdirectory of the Nextcloud installation (file directory). The general recommendation is that the data directory should not be located somewhere in the web folder of your webserver (usually */var/www/*), but in a different folder (e.g. */var/nextcloud_data*). For more information, see [here](https://docs.nextcloud.com/server/15/admin_manual/installation/installation_wizard.html#data-directory-location-label). - However, if your data directory *is* located under the Nextcloud file directory, you'll have to change the scripts so that the data directory is not part of the backup/restore (otherwise, it would be copied twice). - The scripts only backup the Nextcloud data directory. If you have any external storage mounted in Nextcloud, these directories have to be handled separately. -- If you have enabled 4 byte support (see [Nextcloud Administration Manual](https://docs.nextcloud.com/server/15/admin_manual/configuration_database/mysql_4byte_support.html)) while backup, you have to enable 4 byte support on the target system *before* restoring the backup. -- If you do not want to save the database password in the scripts, remove the variable *dbPassword* and call *mysql* with the *-p* parameter (without password). When calling the scripts manually, you'll be asked for the database password. +- The scripts assume that you are using MySQL/MariaDB as database for Nextcloud. However, it also supports PostreSQL databases. In this case you have to uncomment the parts of backing up/restoring the database. +- You should have enabled 4 byte support (see [Nextcloud Administration Manual](https://docs.nextcloud.com/server/15/admin_manual/configuration_database/mysql_4byte_support.html)) on your Nextcloud database. Otherwise, when you have *not* enabled 4 byte support, you have to edit the restore script, to that the database is not created with 4 byte support enabled. ## Backup -- 2.34.1