forked from opennet/FSBackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_backup.sh
executable file
·125 lines (98 loc) · 3.8 KB
/
create_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
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
#!/usr/bin/env bash
#
# Backup planner running from crontab.
#
# Example line for crontab:
#
# 18 4 * * * /usr/local/fsbackup/create_backup.sh | mail -aFrom:"FROM NAME<from_example@example.com>" -s "Backup Report: $(hostname), $(hostname -I | awk '{print $1}')" to_example@example.com
#--------------------------------------
# Path where fsbackup installed.
#--------------------------------------
backup_path="/usr/local/fsbackup"
#--------------------------------------
# List of fsbackup configuration files, delimited by spaces.
# Directories for saving backup in each configuration file should differ
# ($cfg_remote_path, $cfg_local_path), saving multiple backups described by different .conf files
# in the same directory is not allowed is not acceptable.
#--------------------------------------
config_files="cfg_example cfg_example_users cfg_example_sql"
#--------------------------------------
# MySQL table backup flag, 1 - run ./scripts/mysql_backup.sh script (you need edit ./scripts/mysql_backup.sh first!), 0 - not run.
#--------------------------------------
backup_mysql=0
#--------------------------------------
# PostgreSQL table backup flag, 1 - run ./scripts/pgsql_backup.sh script (you need edit ./scripts/pgsql_backup.sh first!), 0 - not run.
#--------------------------------------
backup_pgsql=0
#--------------------------------------
# SQLite table backup flag, 1 - run ./scripts/sqlite_backup.sh script (you need edit ./scripts/sqlite_backup.sh first!), 0 - not run.
#--------------------------------------
backup_sqlite=0
#--------------------------------------
# System parameters backup flag, 1 - run ./scripts/sysbackup.sh script (you need edit ./scripts/sysbackup.sh first!), 0 - not run.
#--------------------------------------
backup_sys=0
#--------------------------------------
# 1 - run mount-windows-share.sh script (you need edit mount-windows-share.sh first!), 0 - not run.
#
# Flag to run the script that mounts the Windows share.
# Pre-configuration of the ./scripts/mount-windows-share.sh script is required,
# 1 to run, 0 not to run.
#--------------------------------------
mount_winshare=0
#--------------------------------------
# 1 - run mount-ftps-share.sh script (you need edit mount-ftps-share.sh first!), 0 - not run.
#
# Flag to run the script that mounts the FTPS share.
# Pre-configuration of the ./scripts/mount-ftps-share.sh script is required,
# 1 to run, 0 not to run.
#--------------------------------------
mount_ftpsshare=0
#############################################################################
# Protection against re-running two copies of fsbackup.pl
IDLE=`ps auxwww | grep fsbackup.pl | grep -v grep`
if [ "$IDLE" != "" ]; then
echo "!!!!!!!!!!!!!!! `date` Backup dup"
exit
fi
cd $backup_path
# Saving MySQL databases
if [ $backup_mysql -eq 1 ]; then
./scripts/mysql_backup.sh
fi
# Saving PostgreSQL databases
if [ $backup_pgsql -eq 1 ]; then
./scripts/pgsql_backup.sh
fi
# Saving SQLite databases
if [ $backup_sqlite -eq 1 ]; then
./scripts/sqlite_backup.sh
fi
# Saving system parameters
if [ $backup_sys -eq 1 ]; then
./scripts/sysbackup.sh
fi
# Mount Windows share (wait for it to show up)
if [ $mount_winshare -eq 1 ]; then
./scripts/mount-windows-share.sh || exit 1
fi
# Mount FTPS share (wait for it to show up)
if [ $mount_ftpsshare -eq 1 ]; then
./scripts/mount-ftps-share.sh || exit 1
fi
# Backup.
for cur_conf in $config_files; do
./fsbackup.pl ./$cur_conf
next_iter=`echo "$config_files"| grep "$cur_conf "`
if [ -n "$next_iter" ]; then
sleep 60 # Sleep for 1 minute, let the processor cool down :-)
fi
done
# Unmounting the Windows share.
if [ $mount_winshare -eq 1 ]; then
./scripts/mount-windows-share.sh umount
fi
# Unmounting the FTPS share.
if [ $mount_ftpsshare -eq 1 ]; then
./scripts/mount-ftps-share.sh umount
fi