Repository navigation
Expand file tree
/
Copy pathNextcloudBackup
More file actions
executable file
·677 lines (636 loc) · 19.6 KB
/
Copy pathNextcloudBackup
File metadata and controls
executable file
·677 lines (636 loc) · 19.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#!/usr/local/bin/zsh
#trap "set +x; sleep 3; set -x" DEBUG
#trap 'read -p "run: $BASH_COMMAND"' DEBUG
source "${HOME}/.bash_functions"
STARTTIME=$(date +%s)
STARTTIME2=$(date +%s)
printf "**** Preparing Backup settings."
#
# Bash script for creating backups of Nextcloud.
#
# Version 2.1.0
#
# Usage:
# - With backup directory specified in the script: ./NextcloudBackup.sh
# - With backup directory specified by parameter: ./NextcloudBackup.sh <sourceDirectory> (e.g. ./NextcloudBackup.sh /media/hdd/nextcloud_backup)
#
# 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/
#
case ${1:0:2} in
-v) Verbose="v"
shift ;;
esac
# Start in ${HOME} directory
cd "${HOME}" || exit
EnableMaintenanceMode () {
printf "Switching on maintenance mode..."
sudo -u "${webserverUser}" php "${nextcloudFileDir}"/occ maintenance:mode --on
echo "Done"
echo
}
DisableMaintenanceMode () {
printf "Switching off maintenance mode..."
sudo -u "${webserverUser}" php "${nextcloudFileDir}"/occ maintenance:mode --off
echo "Done"
echo
}
# Capture CTRL+C
trap CtrlC INT
CtrlC () {
MaintenanceStatus="${MaintenanceModeStatus}"
if [[ "${MaintenanceStatus}" == *"Enabled"* ]]; then
read -p "Backup cancelled. Keep maintenance mode --on? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Maintenance mode still enabled."
else
DisableMaintenanceMode
sleep 2
DisableMaintenanceMode
echo "Maintenance mode disabled."
fi
fi
WebServerStatus="$(apachectl status)"
if [[ "${WebServerStatus}" == *"refused"* ]]; then
printf "Starting web server..."
apachectl restart
# systemctl start "${webserverServiceName}"
echo "Done"
else
echo "Web server is running..."
fi
echo
}
#
# IMPORTANT
# You have to customize this script (directories, users, etc.) for your actual environment.
# All entries which need to be customized are tagged with "TODO".
#
# ************************************************
# Variables
# ************************************************
# TODO: Set these variables to control the backup
DB="db"
MaintenanceModeOn=false
disableWebServer=false
backupFileDir=true
backupInternalData=false
backupExternalData=true
backupDatabase=true
currentDate=$(date +"%Y%m%d")
yesterdayDate=$(date --date="yesterday" +"%Y%m%d")
baseDirName=${1:-ncBackup}
# The actual directories of the current backup - this is a subdirectory of the main directory above with a timestamp
rcDrive="DropBox"
rbaseDir="${rcDrive}:/${baseDirName}"
remoteDir="${rbaseDir}/${currentDate}"
lremoteDir="/home/Cloud/${rcDrive}/${baseDirName}/${currentDate}"
lbaseDir="/${baseDirName}"
sourceDir="${lbaseDir}/${currentDate}"
BackupStepFile="${lbaseDir}/BackupStep"
# Check if DropBox Remote is mounted
#printf "%s" " Checking if ${rcDrive}: is mounted..."
#rclonemount ${DB} >/dev/null 2>&1
#results=$?
#if [[ results -eq 0 ]]; then
# echo "Done"
#else
# printf "%s\n" "Error (${results})"
#fi
# TODO: Use compression for Matrix Synapse installation/lib dir
# When this is the only script for backups, it's recommend to enable compression.
# If the output of this script is used in another (compressing) backup (e.g. borg backup),
# you should probably disable compression here and only enable compression of your main backup script.
useCompression=true
# TODO: Ignore updater's backup directory in the data directory to save space
# Set to true to ignore the backup directory
ignoreUpdaterBackups=true
# TODO: Ignore files in tarball
# Exclude these files
ExcludeTheseFiles="--exclude-from=/root/scripts/NextcloudBackup-Exclude"
# TODO: The directory of your Nextcloud installation (this is a directory under your web root)
nextcloudFileDir='/home/y4x/public_html/nextcloud'
# TODO: The directory of your Nextcloud data directory (outside the Nextcloud file directory)
# If your data directory is located under Nextcloud's file directory (somewhere in the web root), the data directory should not be a separate part of the backup
nextcloudDataDir='/home/y4x/public_html/nextcloud/data'
# TODO: The directory of your Nextcloud's local external storage.
# Uncomment if you use local external storage.
nextcloudLocalExternalDataDir='/var/nc_data'
# TODO: The service name of the web server. Used to start/stop web server (e.g. 'systemctl start <webserverServiceName>')
#webserverServiceName='nginx'
#webserverServiceName='apache'
# TODO: Your web server user
webserverUser='y4x'
# TODO: The name of the database system (one of: mysql, mariadb, postgresql)
databaseSystem='mariadb'
# TODO: Your Nextcloud database name
nextcloudDatabase='y4x_nc_data'
# TODO: Your Nextcloud database user
dbUser='y4x_nc_user'
# TODO: The password of the Nextcloud database user
dbPassword='bokstari46'
# TODO: The maximum number of backups to keep (when set to 0, all backups are kept)
maxNrOfBackups=2
# File names for backup files
# If you prefer other file names, you'll also have to change the NextcloudRestore.sh script.
if [ "$useCompression" = true ] ; then
fileNameBackupFileDir='nextcloud-filedir.tgz'
fileNameBackupDataDir='nextcloud-datadir.tgz'
else
fileNameBackupFileDir='nextcloud-filedir.tar'
fileNameBackupDataDir='nextcloud-datadir.tar'
fi
# TODO: Uncomment if you use local external storage
if [ "$useCompression" = true ] ; then
fileNameBackupExternalDataDir='nextcloud-external-datadir.tgz'
else
fileNameBackupExternalDataDir='nextcloud-external-datadir.tar'
fi
fileNameBackupDb='nextcloud-db.sql'
#
# Check for root
#
echo " ** Check if root user"
if [ "$(id -u)" != "0" ]
then
echo " ERROR: This script must be run as root!"
exit 1
else
echo " User is root"
fi
# Enable maintenance mode
echo " ** Maintenance Mode Check"
if [ "${MaintenanceModeOn}" = true ]; then
printf " Enabling Maintenance Mode..."
EnableMaintenanceMode
results=$?
if [[ results -eq 0 ]]; then
echo "Done (ON)"
MaintenanceModeStatus="Enabled"
else
echo "Errors."
exit
fi
else
echo " Maintenance Mode (OFF)"
MaintenanceModeStatus="Off"
fi
#echo
#
# Stop web server
#
echo " ** Web Server Check"
if [ "${disableWebServer}" = true ]; then
printf " Stopping web server..."
apachectl stop
# systemctl stop "${webserverServiceName}"
results=$?
if [[ results -eq 0 ]]; then
echo "Done"
else
echo "Errors."
fi
else
echo " Web server is still running"
fi
#echo
if [ -e "${BackupStepFile}" ]; then
BackupStep=$(cat "${BackupStepFile}")
fi
# Step 0
#
if [[ -z ${BackupStep} ]] || [[ BackupStep -lt 2 ]]; then
#
# Check if local backup dir already exists give overwrite warning
#
# printf "%s\n" " ** Check if local Backup Directory ${sourceDir} Exists."
if [ -d "${sourceDir}" ]; then
# printf "%s\n" " WARNING: ${sourceDir} already exists!"
# printf "%s" " Deleting ${sourceDir} & ${BackupStepFile}..."
( rm -rf "${sourceDir}"
rm -f "${BackupStepFile}" ) && echo "Done." || echo "Error."
printf "%s" " Creating ${sourceDir}..."
mkdir -p "${sourceDir}" && echo "Done." || echo "Error."
else
printf "%s" " Creating ${sourceDir}..."
mkdir -p "${sourceDir}" && echo "Done." || echo "Error."
fi
BackupStep=0
echo $BackupStep > "${BackupStepFile}"
else
echo " Skip Checking If ${sourceDir} Exists."
fi
#echo
# Step 1
#
#if [[ $BackupStep -lt 5 ]]; then
# #
# # Check if remote backup dir already exists
# #
# printf "%s\n" " ** Check if ${remoteDir} Exists."
# ls -d ${lremoteDir} >/dev/null 2>&1
# results=$?
# if [[ results -eq 0 ]]; then
# printf "%s\n" " WARNING: ${remoteDir} already exists!"
# printf "%s\n" " Backup will Overwrite ${remoteDir}."
# else
# printf "%s\n" " ${remoteDir} will be created automatically"
# fi
# if [[ BackupStep -lt 1 ]]; then
# BackupStep=1
# echo $BackupStep > "${BackupStepFile}"
# fi
#else
# echo " Skipping Remote Backup Directory Exists check."
#fi
##echo
#STOPTIME2=$(($(date +%s)-STARTTIME2))
#show_time ${STOPTIME2} " ** Nextcloud Backup Preparation completed in"
STOPTIME2=$(($(date +%s)-STARTTIME2))
show_time ${STOPTIME2} " ** Backup Preparation completed in"
#echo
# Step 2
#
STARTTIME2=$(date +%s)
if [[ BackupStep -lt 2 ]] && [ "${backupFileDir}" = true ]; then
# Backup home directory
#
echo "**** Backup Nextcloud Home Directory"
printf " ** Creating backup of Nextcloud Home Directory..."
if [ "$useCompression" = true ] ; then
tar -cpzf "${sourceDir}/${fileNameBackupFileDir}" ${ExcludeTheseFiles} -C "${nextcloudFileDir}" . 2>${HOME}/NextcloudBackup.err
else
tar -cpf "${sourceDir}/${fileNameBackupFileDir}" ${ExcludeTheseFiles} -C "${nextcloudFileDir}" . 2>>${HOME}/NextcloudBackup.err
fi
results=$?
if [[ results -eq 0 ]] || [[ results -eq 1 ]]; then
echo "Done"
else
echo "Error"
exit
fi
# echo
if [[ BackupStep -lt 2 ]]; then
BackupStep=2
echo $BackupStep > "${BackupStepFile}"
fi
else
echo " Skipping backup of Nextcloud Home Directory."
fi
STOPTIME2=$(($(date +%s)-STARTTIME2))
show_time ${STOPTIME2} " ** Backup of Nextcloud Home Directed completed in"
#echo
# Step 3
#
STARTTIME2=$(date +%s)
if [[ BackupStep -lt 3 ]] && [ "${backupInternalData}" = true ]; then
#
# Backup Local Internal Data directory
#
echo "**** Backup Nextcloud Local Internal Data Directory"
if [ "$ignoreUpdaterBackups" = true ]; then
echo " ** Ignoring updater backup directory"
printf " ** Creating backup of Nextcloud Internal data directory..."
if [ "$useCompression" = true ] ; then
tar -cpzf "${sourceDir}/${fileNameBackupDataDir}" ${ExcludeTheseFiles} --exclude="updater-*" -C "${nextcloudDataDir}" . 2>>${HOME}/NextcloudBackup.err
else
tar -cpf "${sourceDir}/${fileNameBackupDataDir}" ${ExcludeTheseFiles} --exclude="updater-*" -C "${nextcloudDataDir}" . 2>>${HOME}/NextcloudBackup.err
fi
else
printf " ** Creating backup of Nextcloud Internal data directory..."
if [ "$useCompression" = true ] ; then
tar -cpzf "${sourceDir}/${fileNameBackupDataDir}" ${ExcludeTheseFiles} -C "${nextcloudDataDir}" . 2>>${HOME}/NextcloudBackup.err
else
tar -cpf "${sourceDir}/${fileNameBackupDataDir}" ${ExcludeTheseFiles} -C "${nextcloudDataDir}" . 2>>${HOME}/NextcloudBackup.err
fi
fi
results=$?
if [[ results -eq 0 ]] || [[ results -eq 1 ]]; then
echo "Done"
# echo
else
echo "Fatal tar Error"
# echo
exit
fi
if [[ BackupStep -lt 3 ]]; then
BackupStep=3
echo $BackupStep > "${BackupStepFile}"
fi
else
echo "**** Skipping Nextcloud local Data Directory backup."
fi
STOPTIME2=$(($(date +%s)-STARTTIME2))
show_time ${STOPTIME2} " ** Backup of Internal Data completed in"
#echo
# Step 4
#
STARTTIME2=$(date +%s)
if [[ BackupStep -lt 4 ]] && [ "${backupExternalData}" = true ]; then
#
# Backup Local External Data Directory
#
echo "**** Backup Nextcloud Local External Data Directory"
if [ "${backupExternalData}" = true ]; then
if [ "$ignoreUpdaterBackups" = true ]; then
echo " ** Ignoring updater backup directory"
printf " ** Creating backup of Nextcloud local External Data Directory..."
if [ "$useCompression" = true ]; then
tar -cpzf "${sourceDir}/${fileNameBackupExternalDataDir}" ${ExcludeTheseFiles} --exclude="updater-*/backups/*" -C "${nextcloudLocalExternalDataDir}" . 2>>${HOME}/NextcloudBackup.err
else
tar -cpf "${sourceDir}/${fileNameBackupExternalDataDir}" ${ExcludeTheseFiles} --exclude="updater-*/backups/*" -C "${nextcloudLocalExternalDataDir}" . 2>>${HOME}/NextcloudBackup.err
fi
else
printf " ** Creating backup of Nextcloud local External Data Directory..."
if [ "$useCompression" = true ]; then
tar -cpzf "${sourceDir}/${fileNameBackupExternalDataDir}" ${ExcludeTheseFiles} -C "${nextcloudLocalExternalDataDir}" . 2>>${HOME}/NextcloudBackup.err
else
tar -cpf "${sourceDir}/${fileNameBackupExternalDataDir}" ${ExcludeTheseFiles} -C "${nextcloudLocalExternalDataDir}" . 2>>${HOME}/NextcloudBackup.err
fi
fi
results=$?
if [[ results -eq 0 ]] || [[ results -eq 1 ]]; then
echo "Done"
else
echo "Fatal tar Error"
exit $results
fi
# echo
else
echo " Skipping Nextcloud Local External Data Directory backup."
fi
if [[ BackupStep -lt 4 ]]; then
BackupStep=4
echo $BackupStep > "${BackupStepFile}"
fi
else
echo " Skipping Nextcloud Local External Data Directory backup."
fi
STOPTIME2=$(($(date +%s)-STARTTIME2))
show_time ${STOPTIME2} " ** Backup of External Data Directory completed in"
#echo
# Step 5
# Split file into 30G parts
# Either Internal or External data backup must be "true"
STARTTIME2=$(date +%s)
if [[ BackupStep -lt 5 ]]; then
if [ "${backupInternalData}" = true ]; then
SplitFile=${fileNameBackupDataDir}
else
SplitFile=${fileNameBackupExternalDataDir}
fi
rclonemount ${DB} >/dev/null 2>&1
cd "${sourceDir}" || exit
FileSize="30G"
fSize=$(echo ${FileSize} | numfmt --from=iec)
FileToCheck=${SplitFile}
if [ -n "${Verbose}" ]; then
# NextcloudBackup Log file name
ncBackupLogRaw='ncBackupRaw.log'
ncBackupLogFull='ncBackupFull.log'
ncBackupLogShort='ncBackupShort.log'
tar -tvzf ${FileToCheck} 1> ${ncBackupLogRaw} 2>/dev/null 1> ${ncBackupLogRaw} 2>/dev/null
cat ${ncBackupLogRaw} |awk -v FIELDWIDTHS="10 8 13 10 6 *" \
'{printf "%s\t %9.3fM\t %s\t %s\t %s\n", $3, val = $3/1024/1024, $4, $5, $6}' 1> ${ncBackupLogFull} 2>/dev/null
cat ${ncBackupLogRaw} |awk -v FIELDWIDTHS="10 8 13 10 6 *" \
'{printf "%9.3fM\t %s\n", val = $3/1024/1024, $6}' 1> ${ncBackupLogShort} 2>/dev/null
fi
ThisFileSize=$(stat -c %s "${FileToCheck}")
echo "**** Checking File Size"
if [[ ThisFileSize -gt fSize ]]; then
printf "%s\n" " ** File Size > ${FileSize}"
printf "%s" " ** Spliting ${FileToCheck} into ${FileSize} parts..."
( split -d -b ${FileSize} "${FileToCheck}" "${FileToCheck}.part" >/dev/null 2>&1 )
results=$?
if [[ results -eq 0 ]]; then
echo "Done"
printf "%s" " ** Deleting ${FileToCheck}..."
rm -f ${FileToCheck} >/dev/null 2>&1 && echo "Done." || echo "Errors."
else
echo "Errors"
printf "%s\n" " ${FileToCheck} NOT Removed!"
fi
# echo
# ls -hl ${FileToCheck}*|indent 3 2
# echo
fi
if [[ BackupStep -lt 5 ]]; then
BackupStep=5
echo $BackupStep > "${BackupStepFile}"
fi
else
echo " Skipping Split File of Backup."
fi
STOPTIME2=$(($(date +%s)-STARTTIME2))
show_time ${STOPTIME2} " ** Spliting ${FileToCheck} completed in"
#echo
# Step 6
#
STARTTIME2=$(date +%s)
if [[ BackupStep -lt 6 ]]; then
#
# Backup ${DB}
#
echo "**** Nextcloud Database"
if [ "${backupDatabase}" = true ]; then
if [ "${databaseSystem}" = "mysql" ] || [ "${databaseSystem}" = "mariadb" ]; then
printf "%s" " ** Backup Nextcloud database (MySQL/MariaDB)..."
if ! [ -x "$(command -v mariadb-dump)" ]; then
printf "\n%s\n" "ERROR: MySQL/MariaDB not installed (command mariadb-dump not found)."
echo "ERROR: No backup of database possible!"
else
mariadb-dump --single-transaction -h localhost -u "${dbUser}" -p"${dbPassword}" "${nextcloudDatabase}" > "${sourceDir}/${fileNameBackupDb}"
fi
echo "Done"
elif [ "${databaseSystem}" = "postgresql" ] || [ "${databaseSystem}" = "pgsql" ]; then
printf "%s" " Backup Nextcloud database (PostgreSQL)..."
if ! [ -x "$(command -v pg_dump)" ]; then
echo "ERROR: PostgreSQL not installed (command pg_dump not found)."
echo "ERROR: No backup of database possible!"
else
PGPASSWORD="${dbPassword}" pg_dump "${nextcloudDatabase}" -h localhost -U "${dbUser}" \
-f "${sourceDir}/${fileNameBackupDb}"
fi
results=$?
if [[ results -eq 0 ]]; then
echo "Done"
else
echo "Errors."
fi
fi
# echo
if [[ BackupStep -lt 6 ]]; then
BackupStep=6
echo $BackupStep > "${BackupStepFile}"
fi
else
echo " Skipping ${DB} Backup."
fi
else
echo " Skipping ${DB} backup."
fi
STOPTIME2=$(($(date +%s)-STARTTIME2))
show_time ${STOPTIME2} " ** Backup Nextcloud MySQL ${DB} completed in"
#echo
# Step 7
#
STARTTIME2=$(date +%s)
if [[ BackupStep -eq 6 ]]; then
#
# Move backup to remote ${remoteDir}
#
( CMD="moveto"
cd ${lbaseDir}
echo "**** Moving Nextcloud Backup to ${RemoteDir}"
printf "%s" " ** rclone ${CMD} [From:]${currentDate} [To:]${remoteDir}..."
rclone \
--log-file "/var/log/rclone.log" \
--log-level=DEBUG \
--cache-dir=${HOME}/.cache/rclone/cron/${DB}-${USER} \
--cache-db-path=${HOME}/.cache/rclone/cron/${DB}-${USER}/cache-backend \
--buffer-size=128M \
--transfers=64 \
--use-mmap \
--drive-use-trash=false \
--drive-disable-http2=false \
--cache-db-purge=true \
--dropbox-batch-mode=sync \
--dropbox-chunk-size=128M \
${CMD} ${currentDate} ${remoteDir}
results=$?
if [[ results -eq 0 ]]; then
echo "Done"
printf "%s" " ** Deleting local ${sourceDir}..."
rm -rf ${sourceDir} >/dev/null 2>&1 && echo "Done" || echo "Errors"
else
echo "Errors."
fi
# echo
# echo
)
if [[ BackupStep -lt 7 ]]; then
BackupStep=7
echo $BackupStep > "${BackupStepFile}"
fi
else
echo " Skipping Nextcloud backup Move to Remote."
# echo
fi
STOPTIME2=$(($(date +%s)-STARTTIME2))
show_time ${STOPTIME2} " ** Moving of Backup to ${remoteDir} completed in"
# Step 8
#
# Final cleanup of backups files
#
STARTTIME2=$(date +%s)
if [[ BackupStep -eq 7 ]]; then
#
# Start web serv
#
echo "**** Final cleanup of Backup Files"
echo " ** Check Web Server"
if [ ${disableWebServer} = true ]; then
printf " ** Starting web server..."
apachectl restart >/dev/null
results=$?
if [[ results -eq 0 ]]; then
echo "Done"
else
echo "Errors."
fi
else
echo " Web server is still running."
fi
if [[ BackupStep -lt 8 ]]; then
BackupStep=8
echo $BackupStep > "${BackupStepFile}"
fi
# echo
fi
# Step 9
#
if [[ BackupStep -eq 8 ]]; then
#
# Disable maintenance mode
#
echo " ** Check Nextcloud Maintenancce Mode"
if [ "${MaintenanceModeOn}" = true ]; then
printf " Disabling Maintenance Mode (OFF)..."
DisableMaintenanceMode
results=$?
if [[ results -eq 0 ]]; then
echo "Done"
else
echo "Errors."
fi
else
echo " Maintenance Mode (OFF)"
fi
if [[ BackupStep -lt 9 ]]; then
BackupStep=9
echo $BackupStep > "${BackupStepFile}"
fi
# echo
fi
# Step 10
#
if [[ $BackupStep -eq 9 ]]; then
#
# Delete old backups
#
echo "**** Delete Old Nextcloud Backups"
if [[ maxNrOfBackups -ne 0 ]]; then
nrOfBackups=$(rclone lsf ${rbaseDir} --max-depth 1 | wc -l)
if [[ nrOfBackups -gt maxNrOfBackups ]]; then
echo " ** Removing old backups"
rclone lsf ${rbaseDir} --max-depth 1 | sort -r | tail -$(( nrOfBackups - maxNrOfBackups )) |
while read -r dirToRemove; do
printf "%s" " rclone purge ${rbaseDir}/${dirToRemove}..."
rclone purge ${rbaseDir}/${dirToRemove} --drive-use-trash=false
results=$?
if [[ results -eq 0 ]]; then
echo "Done"
else
echo "Errors."
fi
done
else
echo " ** No Old Backups to Delete"
fi
fi
# echo
if [[ BackupStep -lt 10 ]]; then
BackupStep=10
echo $BackupStep > "${BackupStepFile}"
fi
else
echo " Skip Delete Old Nextcloud Backups."
fi
STOPTIME2=$(($(date +%s)-STARTTIME2))
show_time ${STOPTIME2} " ** Backup Final cleanup completed in"
#echo
# Step 11
#
if [[ BackupStep -eq 10 ]]; then
printf "%s\n" "List of files on ${rbaseDir}:"
# ( echo "----------------"
# rclone tree ${rbaseDir} -asD --human-readable #| grep -v 'tgz'
# )
echo "----------------"
echo "New Files in this Backup (diffraw)."
echo "----------------"
diffshort # see also diffraw, difffull and diffshort
printf "%s\n" "**** ${remoteDir} Backup DONE!"
rm -f "${BackupStepFile}" >/dev/null 2>&1
echo "----------------"
echo "Listing of ${lbaseDir} - Should be empty."
ls ${lbaseDir}
echo "----------------"
# echo
fi
#echo
if [ ! -s ${HOME}/NextcloudBackup.err ]; then
rm -f ${HOME}/NextcloudBackup.err >/dev/null 2>&1
fi
STOPTIME=$(($(date +%s)-STARTTIME))
show_time ${STOPTIME} "**** Nextcloud Backup completed in"