-
Notifications
You must be signed in to change notification settings - Fork 6
/
backup.sh
70 lines (65 loc) · 4.06 KB
/
backup.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /bin/bash
# Be sure to set this variable to what your webserver user is. Typically it will be www-data or nginx
# webserver_user=
if ! command -v mysqldump &> /dev/null
then
echo "+------------------------------------------------------------------------------------------+"
echo "| mysqldump is required to run this script |"
echo "| Try installing either mysql-server or mariadb-server to correct this |"
echo "+------------------------------------------------------------------------------------------+"
exit
fi
# Set this to the location you'd like backups placed, be sure to leave off the trailing /
backup_dir="/tmp"
# If you want to change how the date is displayed edit this line
backup_dir_date=$backup_dir/backup-$(date +"%Y-%m-%d--%H-%M-%S")
backup_file=$backup_dir/backup-$(date +"%Y-%m-%d--%H-%M-%S").tar.gz
if [ -f /.dockerenv ]
then
echo "+------------------------------------------------------------------------------------------+"
echo "Docker detected"
echo "+------------------------------------------------------------------------------------------+"
su -s /bin/bash -c "mkdir $backup_dir_date" www-data
echo "Taking database backup and storing in $backup_dir_date"
su -s /bin/bash -c "./bin/cake passbolt mysql_export --dir $backup_dir_date" www-data
echo "+------------------------------------------------------------------------------------------+"
echo "Copying /etc/environment to $backup_dir_date"
echo "+------------------------------------------------------------------------------------------+"
cp /etc/environment $backup_dir_date/.
else
if [ -z ${webserver_user} ]
then
echo "+------------------------------------------------------------------------------------------+"
echo "| You don't have the webserver_user set in the backup.sh file |"
echo "| Please correct this and then re-run this script |"
echo "+------------------------------------------------------------------------------------------+"
exit
fi
echo "+------------------------------------------------------------------------------------------+"
echo "Docker not detected"
echo "+------------------------------------------------------------------------------------------+"
su -s /bin/bash -c "mkdir $backup_dir_date" $webserver_user
echo "Taking database backup and storing in $backup_dir_date"
echo "+------------------------------------------------------------------------------------------+"
su -s /bin/bash -c "/usr/share/php/passbolt/bin/cake passbolt mysql_export --dir $backup_dir_date" $webserver_user
echo "+------------------------------------------------------------------------------------------+"
echo "Copying /etc/passbolt/passbolt.php to $backup_dir_date"
echo "+------------------------------------------------------------------------------------------+"
cp /etc/passbolt/passbolt.php $backup_dir_date/.
fi
echo "Copying /etc/passbolt/gpg/serverkey_private.asc to $backup_dir_date"
echo "+------------------------------------------------------------------------------------------+"
cp /etc/passbolt/gpg/serverkey_private.asc $backup_dir_date/.
echo "Copying /etc/passbolt/gpg/serverkey.asc to $backup_dir_date"
echo "+------------------------------------------------------------------------------------------+"
cp /etc/passbolt/gpg/serverkey.asc $backup_dir_date/.
echo "Creating archive of $backup_dir_date"
echo "+------------------------------------------------------------------------------------------+"
tar -czvf $backup_dir_date.tar.gz -C $backup_dir_date .
echo "+------------------------------------------------------------------------------------------+"
echo "Cleaning up $backup_dir"
echo "+------------------------------------------------------------------------------------------+"
rm $backup_dir_date/*
rmdir $backup_dir_date
echo "Backup completed you can find the file as $backup_file"
echo "+------------------------------------------------------------------------------------------+"