]>
git.p6c8.net - nextcloud-backup-restore.git/blob - setup.sh
1462ea51d6c6d950e01ad95cfec7b022d6333636
4 # Bash script an easy setup of NextcloudBackup.sh and NextcloudRestore.sh
9 # - call the setup.sh script
10 # - Enter the required information
11 # - You NextcloudBackup.sh and NextcloudRestore.sh scripts will be tailored to match you installation.
13 # The script is based on an installation of Nextcloud using nginx and MariaDB, see https://decatec.de/home-server/nextcloud-auf-ubuntu-server-18-04-lts-mit-nginx-mariadb-php-lets-encrypt-redis-und-fail2ban/
18 # The setup.sh script automated the configuration for the backup/restore scripts.
19 # However, you should always check the backup/restore scripts BEFORE executing these!
23 # Pre defined variables
25 backupMainDir
= '/media/hdd/nextcloud_backup'
26 nextcloudFileDir
= '/var/www/nextcloud'
27 webserverUser
= 'www-data'
28 webserverServiceName
= 'nginx'
35 echo "Enter the directory to which the backups should be saved."
36 echo "Default: ${backupMainDir} "
38 read -p "Enter a directory or press ENTER if the backup directory should be ${backupMainDir} : " BACKUPMAINDIR
40 [ -z " $BACKUPMAINDIR " ] || backupMainDir
= $BACKUPMAINDIR
43 echo "Enter the path to the Nextcloud file directory."
44 echo "Usually: ${nextcloudFileDir} "
46 read -p "Enter a directory or press ENTER if the file directory is ${nextcloudFileDir} : " NEXTCLOUDFILEDIRECTORY
48 [ -z " $NEXTCLOUDFILEDIRECTORY " ] || nextcloudFileDir
= $NEXTCLOUDFILEDIRECTORY
51 echo "Enter the webserver user."
52 echo "Usually: ${webserverUser} "
54 read -p "Enter an new user or press ENTER if the webserver user is ${webserverUser} : " WEBSERVERUSER
56 [ -z " $WEBSERVERUSER " ] || webserverUser
= $WEBSERVERUSER
59 echo "Enter the webserver service name."
60 echo "Usually: nginx or apache2"
62 read -p "Enter an new webserver service name or press ENTER if the webserver user is ${webserverUser} : " WEBSERVERSERVICENAME
64 [ -z " $WEBSERVERSERVICENAME " ] || webserverServiceName
= $WEBSERVERSERVICENAME
67 echo "Backup directory: ${backupMainDir} "
68 echo "Nextcloud file directory: ${nextcloudFileDir} "
69 echo "Webserver user: ${webserverUser} "
71 read -p "Is the information correct? [y/N] " CORRECTINFO
73 if [ " $CORRECTINFO " != 'y' ] ; then
75 echo "No file has been altered."
80 sudo
-u " ${webserverUser} " php
${nextcloudFileDir} / occ config
: system
: get
" $1 "
83 # Make test call to OCC
87 echo "Error calling OCC: Please check if the information provided was correct."
89 echo "No file has been altered."
94 # Read data from OCC and write to backup/restore scripts.
99 echo "Modifying NextcloudBackup.sh and NextcloudRestore.sh to match your installation..."
103 sed -i "s@^ backupMainDir.*@ backupMainDir=' $backupMainDir '@" .
/ NextcloudBackup.sh
104 sed -i "s@^ backupMainDir.*@ backupMainDir=' $backupMainDir '@" .
/ NextcloudRestore.sh
107 sed -i "s@^nextcloudFileDir.*@nextcloudFileDir=' $nextcloudFileDir '@" .
/ NextcloudBackup.sh
108 sed -i "s@^nextcloudFileDir.*@nextcloudFileDir=' $nextcloudFileDir '@" .
/ NextcloudRestore.sh
111 nextcloudDataDir
= $
( occ_get datadirectory
)
113 sed -i "s@^nextcloudDataDir=.*@nextcloudDataDir=' $nextcloudDataDir '@" .
/ NextcloudBackup.sh
114 sed -i "s@^nextcloudDataDir=.*@nextcloudDataDir=' $nextcloudDataDir '@" .
/ NextcloudRestore.sh
116 # Webserver service name
117 sed -i "s/^webserverServiceName.*/webserverServiceName=' $webserverServiceName '/" .
/ NextcloudBackup.sh
118 sed -i "s/^webserverServiceName.*/webserverServiceName=' $webserverServiceName '/" .
/ NextcloudRestore.sh
121 sed -i "s/^webserverUser.*/webserverUser=' $webserverUser '/" .
/ NextcloudBackup.sh
122 sed -i "s/^webserverUser.*/webserverUser=' $webserverUser '/" .
/ NextcloudRestore.sh
125 databaseSystem
= $
( occ_get dbtype
)
127 # PostgreSQL is identified as pgsql
128 if [ " ${databaseSystem,,} " = "pgsql" ]; then
129 databaseSystem
= 'postgresql' ;
132 sed -i "s/^databaseSystem.*/databaseSystem=' $databaseSystem '/" .
/ NextcloudBackup.sh
133 sed -i "s/^databaseSystem.*/databaseSystem=' $databaseSystem '/" .
/ NextcloudRestore.sh
136 nextcloudDatabase
= $
( occ_get dbname
)
138 sed -i "s/^nextcloudDatabase.*/nextcloudDatabase=' $nextcloudDatabase '/" .
/ NextcloudBackup.sh
139 sed -i "s/^nextcloudDatabase.*/nextcloudDatabase=' $nextcloudDatabase '/" .
/ NextcloudRestore.sh
142 dbUser
= $
( occ_get dbuser
)
144 sed -i "s/^dbUser.*/dbUser=' $dbUser '/" .
/ NextcloudBackup.sh
145 sed -i "s/^dbUser.*/dbUser=' $dbUser '/" .
/ NextcloudRestore.sh
148 dbPassword
= $
( occ_get dbpassword
)
150 sed -i "s/^dbPassword.*/dbPassword=' $dbPassword '/" .
/ NextcloudBackup.sh
151 sed -i "s/^dbPassword.*/dbPassword=' $dbPassword '/" .
/ NextcloudRestore.sh
157 echo "IMPORTANT: Please check NextcloudBackup.sh and NextcloudRestore.sh if all variables were set correctly BEFORE running these scripts!"
patrick-canterino.de