-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmysql-dump.sh
executable file
·42 lines (34 loc) · 925 Bytes
/
mysql-dump.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
#!/bin/bash
# -*- coding: UTF-8 -*-
# Script for dumping MySQL base automatically using cron.
# exec test
exec_test () {
[ $? -eq 0 ] && echo "-- Command successfully executed" || echo "-- Command failed; exit 1"
}
# Filenames
database_name="test"
backup_folder="/path/to/backup/folder/"
mydate=`date '+%m%d%y'`
mytime=`date '+%T %m.%d.%y.'`
filename1="$backup_folder/$database_name_$mydate.bck.sql"
username="some"
password="emos"
# Logging
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>>$backup_folder/$database_name.log 2>&1
# Everything below will go to the log file
dump_base () {
echo "###########################"
echo "STARTING on: $mytime"
echo "Base dumping..."
mysqldump -u$username -p$password $database_name > $filename1
}
compress_base () {
echo "Compressing base..."
gzip -f9 $filename1
# rm filename1
}
dump_base ; exec_test
compress_base ; exec_test
echo "Done, quit!"