From: DecaTec Date: Sat, 13 Jun 2020 10:33:21 +0000 (+0200) Subject: Setup: user is asked for webserver name; X-Git-Tag: v2.1.0~3^2~2 X-Git-Url: https://git.p6c8.net/nextcloud-backup-restore.git/commitdiff_plain/343e0030aec4e9213a9d432580197510d1f008be?ds=inline;hp=-c Setup: user is asked for webserver name; DB system can now also be pqsql --- 343e0030aec4e9213a9d432580197510d1f008be diff --git a/NextcloudBackup.sh b/NextcloudBackup.sh index 76ca676..47abd13 100644 --- a/NextcloudBackup.sh +++ b/NextcloudBackup.sh @@ -195,7 +195,7 @@ if [ "${databaseSystem,,}" = "mysql" ] || [ "${databaseSystem,,}" = "mariadb" ]; echo "Done" echo -elif [ "${databaseSystem,,}" = "postgresql" ]; then +elif [ "${databaseSystem,,}" = "postgresql" ] || [ "${databaseSystem,,}" = "pgsql" ]; then echo "Backup Nextcloud database (PostgreSQL)..." if ! [ -x "$(command -v pg_dump)" ]; then diff --git a/NextcloudRestore.sh b/NextcloudRestore.sh index 3b60676..90ec545 100644 --- a/NextcloudRestore.sh +++ b/NextcloudRestore.sh @@ -111,7 +111,7 @@ if [ "${databaseSystem,,}" = "mysql" ] || [ "${databaseSystem,,}" = "mariadb" ]; errorecho "Cancel restore" exit 1 fi -elif [ "${databaseSystem,,}" = "postgresql" ]; then +elif [ "${databaseSystem,,}" = "postgresql" ] || [ "${databaseSystem,,}" = "pgsql" ]; then if ! [ -x "$(command -v psql)" ]; then errorecho "ERROR: PostgreSQL not installed (command psql not found)." errorecho "ERROR: No restore of database possible!" @@ -206,7 +206,7 @@ if [ "${databaseSystem,,}" = "mysql" ] || [ "${databaseSystem,,}" = "mariadb" ]; mysql -h localhost -u "${dbUser}" -p"${dbPassword}" -e "CREATE DATABASE ${nextcloudDatabase} CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" # TODO: 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}" -elif [ "${databaseSystem,,}" = "postgresql" ]; then +elif [ "${databaseSystem,,}" = "postgresql" ] || [ "${databaseSystem,,}" = "pgsql" ]; then sudo -u postgres psql -c "CREATE DATABASE ${nextcloudDatabase} WITH OWNER ${dbUser} TEMPLATE template0 ENCODING \"UTF8\";" fi @@ -217,7 +217,7 @@ echo "Restoring backup DB..." if [ "${databaseSystem,,}" = "mysql" ] || [ "${databaseSystem,,}" = "mariadb" ]; then mysql -h localhost -u "${dbUser}" -p"${dbPassword}" "${nextcloudDatabase}" < "${currentRestoreDir}/${fileNameBackupDb}" -elif [ "${databaseSystem,,}" = "postgresql" ]; then +elif [ "${databaseSystem,,}" = "postgresql" ] || [ "${databaseSystem,,}" = "pgsql" ]; then sudo -u postgres psql "${nextcloudDatabase}" < "${currentRestoreDir}/${fileNameBackupDb}" fi diff --git a/setup.sh b/setup.sh old mode 100644 new mode 100755 index 9af4338..1462ea5 --- a/setup.sh +++ b/setup.sh @@ -25,24 +25,45 @@ backupMainDir='/media/hdd/nextcloud_backup' nextcloudFileDir='/var/www/nextcloud' webserverUser='www-data' +webserverServiceName='nginx' # # Gather information # -read -p "In which directory the backups should be saved (default: ${backupMainDir}). Enter a directory or press ENTER if the backup directory should be ${backupMainDir}: " BACKUPMAINDIR +clear + +echo "Enter the directory to which the backups should be saved." +echo "Default: ${backupMainDir}" +echo "" +read -p "Enter a directory or press ENTER if the backup directory should be ${backupMainDir}: " BACKUPMAINDIR [ -z "$BACKUPMAINDIR" ] || backupMainDir=$BACKUPMAINDIR +clear -read -p "Enter the path to the Nextcloud file directory (usually ${nextcloudFileDir}). Enter a directory or press ENTER if the file directory is ${nextcloudFileDir}: " NEXTCLOUDFILEDIRECTORY +echo "Enter the path to the Nextcloud file directory." +echo "Usually: ${nextcloudFileDir}" +echo "" +read -p "Enter a directory or press ENTER if the file directory is ${nextcloudFileDir}: " NEXTCLOUDFILEDIRECTORY [ -z "$NEXTCLOUDFILEDIRECTORY" ] || nextcloudFileDir=$NEXTCLOUDFILEDIRECTORY +clear -read -p "Enter the webserver user (usually ${webserverUser}). Enter an new user or press ENTER if the webserver user is ${webserverUser}: " WEBSERVERUSER +echo "Enter the webserver user." +echo "Usually: ${webserverUser}" +echo "" +read -p "Enter an new user or press ENTER if the webserver user is ${webserverUser}: " WEBSERVERUSER [ -z "$WEBSERVERUSER" ] || webserverUser=$WEBSERVERUSER +clear +echo "Enter the webserver service name." +echo "Usually: nginx or apache2" echo "" -echo "" +read -p "Enter an new webserver service name or press ENTER if the webserver user is ${webserverUser}: " WEBSERVERSERVICENAME + +[ -z "$WEBSERVERSERVICENAME" ] || webserverServiceName=$WEBSERVERSERVICENAME +clear + echo "Backup directory: ${backupMainDir}" echo "Nextcloud file directory: ${nextcloudFileDir}" echo "Webserver user: ${webserverUser}" @@ -93,6 +114,8 @@ sed -i "s@^nextcloudDataDir=.*@nextcloudDataDir='$nextcloudDataDir'@" ./Nextclou sed -i "s@^nextcloudDataDir=.*@nextcloudDataDir='$nextcloudDataDir'@" ./NextcloudRestore.sh # Webserver service name +sed -i "s/^webserverServiceName.*/webserverServiceName='$webserverServiceName'/" ./NextcloudBackup.sh +sed -i "s/^webserverServiceName.*/webserverServiceName='$webserverServiceName'/" ./NextcloudRestore.sh # Webserver user sed -i "s/^webserverUser.*/webserverUser='$webserverUser'/" ./NextcloudBackup.sh @@ -101,6 +124,11 @@ sed -i "s/^webserverUser.*/webserverUser='$webserverUser'/" ./NextcloudRestore.s # Database system databaseSystem=$(occ_get dbtype) +# PostgreSQL is identified as pgsql +if [ "${databaseSystem,,}" = "pgsql" ]; then + databaseSystem='postgresql'; +fi + sed -i "s/^databaseSystem.*/databaseSystem='$databaseSystem'/" ./NextcloudBackup.sh sed -i "s/^databaseSystem.*/databaseSystem='$databaseSystem'/" ./NextcloudRestore.sh