-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapexport.sh
51 lines (37 loc) · 1.44 KB
/
snapexport.sh
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
#!/bin/bash
##############################################################
# -scubamuc- https://scubamuc.github.io/ #
# Nextcloud-snap backup with nextcloud.export #
##############################################################
## backup directory: '/var/snap/nextcloud/common/backups'
## restore directory: '/var/snap/nextcloud/common'
## backup rotation 30 days
## create crontab as root for automation
##############################################################
# VARIABLES #
##############################################################
SNAPNAME="nextcloud"
BACKUPNAME="mybackup"
TARGET="/media/SNAPBACKUP" ## target directory
SOURCE="/var/snap/nextcloud/common/backups" ## source directory
RETENTION="30" ## file retention in days
##############################################################
# SCRIPT #
##############################################################
## must be root, enter sudo password
sudo pwd
## create backup with nextcloud.export ##
sudo nextcloud.export ; ## nextcloud.export, see options
## find and compress backup directory ##
list=`ls $SOURCE`
for i in $list
do
if [ ! "$i" == "." ]; then
sudo tar czf ${i}-$BACKUPNAME.tar.gz ${i}
fi
done
## find and move compressed backup file to $TARGET
sudo find $SOURCE/ -name "*.tar.gz" -exec mv '{}' $TARGET/ \;
## find and rotate/delete old backups
sudo find $TARGET/ -name "*.tar.gz" -mtime +$RETENTION -exec rm -f {} \;
exit