]> git.p6c8.net - nextcloud-backup-restore.git/blob - setup.sh
fda55a6204ba88ba815da0f2c3aa3d88f6c03eab
[nextcloud-backup-restore.git] / setup.sh
1 #!/bin/bash
2
3 #
4 # Pre defined variables
5 #
6 backupMainDir='/media/hdd/nextcloud_backup'
7 nextcloudFileDir='/var/www/nextcloud'
8 webserverUser='www-data'
9
10 #
11 # Gather information
12 #
13 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
14
15 [ -z "$BACKUPMAINDIR" ] || backupMainDir=$BACKUPMAINDIR
16
17 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
18
19 [ -z "$NEXTCLOUDFILEDIRECTORY" ] || nextcloudFileDir=$NEXTCLOUDFILEDIRECTORY
20
21 read -p "Enter the webserver user (usually ${webserverUser}). Enter an new user or press ENTER if the webserver user is ${webserverUser}: " WEBSERVERUSER
22
23 [ -z "$WEBSERVERUSER" ] || webserverUser=$WEBSERVERUSER
24
25 echo ""
26 echo ""
27 echo "Backup directory: ${backupMainDir}"
28 echo "Nextcloud file directory: ${nextcloudFileDir}"
29 echo "Webserver user: ${webserverUser}"
30 echo ""
31 read -p "Is the information correct? [y/N] " CORRECTINFO
32
33 if [ "$CORRECTINFO" != 'y' ] ; then
34 echo "ABORTING!"
35 echo "No file has been altered."
36 exit 1
37 fi
38
39 function occ_get() {
40 sudo -u "${webserverUser}" php ${nextcloudFileDir}/occ config:system:get "$1"
41 }
42
43 # Make test call to OCC
44 occ_get datadirectory
45
46 if [ $? -ne 0 ]; then
47 echo "Error calling OCC: Please check if the information provided was correct."
48 echo "ABORTING!"
49 echo "No file has been altered."
50 exit 1
51 fi
52
53 #
54 # Read data from OCC and write to backup/restore scripts.
55 #
56
57 echo ""
58 echo ""
59 echo "Modifying NextcloudBackup.sh and NextcloudRestore.sh to match your installation..."
60 echo ""
61
62 # Backup main dir
63 sed -i "s@^ backupMainDir.*@ backupMainDir='$backupMainDir'@" ./NextcloudBackup.sh
64 sed -i "s@^ backupMainDir.*@ backupMainDir='$backupMainDir'@" ./NextcloudRestore.sh
65
66 # Nextcloud file dir
67 sed -i "s@^nextcloudFileDir.*@nextcloudFileDir='$nextcloudFileDir'@" ./NextcloudBackup.sh
68 sed -i "s@^nextcloudFileDir.*@nextcloudFileDir='$nextcloudFileDir'@" ./NextcloudRestore.sh
69
70 # Nextcloud data dir
71 nextcloudDataDir=$(occ_get datadirectory)
72
73 sed -i "s@^nextcloudDataDir=.*@nextcloudDataDir='$nextcloudDataDir'@" ./NextcloudBackup.sh
74 sed -i "s@^nextcloudDataDir=.*@nextcloudDataDir='$nextcloudDataDir'@" ./NextcloudRestore.sh
75
76 # Webserver service name
77
78 # Webserver user
79 sed -i "s/^webserverUser.*/webserverUser='$webserverUser'/" ./NextcloudBackup.sh
80 sed -i "s/^webserverUser.*/webserverUser='$webserverUser'/" ./NextcloudRestore.sh
81
82 # Database system
83 databaseSystem=$(occ_get dbtype)
84
85 sed -i "s/^databaseSystem.*/databaseSystem='$databaseSystem'/" ./NextcloudBackup.sh
86 sed -i "s/^databaseSystem.*/databaseSystem='$databaseSystem'/" ./NextcloudRestore.sh
87
88 # Database
89 nextcloudDatabase=$(occ_get dbname)
90
91 sed -i "s/^nextcloudDatabase.*/nextcloudDatabase='$nextcloudDatabase'/" ./NextcloudBackup.sh
92 sed -i "s/^nextcloudDatabase.*/nextcloudDatabase='$nextcloudDatabase'/" ./NextcloudRestore.sh
93
94 # Database user
95 dbUser=$(occ_get dbuser)
96
97 sed -i "s/^dbUser.*/dbUser='$dbUser'/" ./NextcloudBackup.sh
98 sed -i "s/^dbUser.*/dbUser='$dbUser'/" ./NextcloudRestore.sh
99
100 # Database password
101 dbPassword=$(occ_get dbpassword)
102
103 sed -i "s/^dbPassword.*/dbPassword='$dbPassword'/" ./NextcloudBackup.sh
104 sed -i "s/^dbPassword.*/dbPassword='$dbPassword'/" ./NextcloudRestore.sh
105
106 echo ""
107 echo "Done!"
108 echo ""
109 echo ""
110 echo "IMPORTANT: Please check NextcloudBackup.sh and NextcloudRestore.sh if all variables were set correctly BEFORE running these scripts!"
111 echo ""
112 echo ""

patrick-canterino.de