-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup-mongo-all-db
More file actions
49 lines (39 loc) · 1.22 KB
/
backup-mongo-all-db
File metadata and controls
49 lines (39 loc) · 1.22 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
#!/bin/bash
#local settings:
days_to_keep="30"
backup_path="/backup/`hostname`/mongo"
#ftp:
ftp_server=''
ftp_user_name=''
ftp_user_pass=''
LANG=C
cmddir=`dirname $0`
cmdname=`basename $0`
newtmpdir="/tmp/${cmdname}"
mkdir -p "${newtmpdir}"
if [ -e ${newtmpdir}/lock ]
then
echo "allready running with lockfile ${newtmpdir}/lock";
exit;
else
touch ${newtmpdir}/lock
fi
function cleanup () {
rm -rf "$newtmpdir"
}
trap 'cleanup' EXIT
trap 'cleanup' SIGTERM
hostname=`hostname`
day=`date +%y%m%d-%H-%M`;
backup_path="${backup_path}/${day}"
mkdir -p ${backup_path} &> /dev/null
cd ${backup_path}; nice -n19 ionice -c 3 mongodump --host localhost &> /dev/null;
if [ $? -ne 0 ]; then
echo "ERROR: mongo database backup FAILED at ${hostname} : ${day} : ${backup_path}"
fi
nice -n19 ionice -c 3 find ${backup_path}/* -type f -ctime +${days_to_keep} | xargs nice -n19 ionice -c 3 rm -f
# then transfer all to ftp:
if [ "${ftp_server}" != "" ]
then
trickle -u 20000 -d 20000 nice -n19 ionice -c 3 lftp -c "set ftp:list-options -a; set ssl:verify-certificate no; open ftp://$ftp_user_name:$ftp_user_pass@$ftp_server; lcd ${backup_path}; mkdir -p ${backup_path}; cd ${backup_path}; mirror --reverse --delete --verbose" &> /dev/null
fi