1
1
#! /bin/bash
2
2
3
- # Script Name : mysql_backup.sh
4
-
5
- # Author : Craig Richards
6
- # Created : 08-March-2012
3
+ # Script Name : mysql_backup.sh
4
+ # Author : Craig Richards
5
+ # Created : 08-March-2012
6
+ # Last Modified :
7
+ # Version : 1.0
7
8
8
9
# Modifications :
9
10
10
- # Description : Backup MySQL database, either the full database or just a single database
11
-
12
- # Instructions : mysql_backup.sh full or mysql_backup.sh db db_name
11
+ # Description : Backup MySQL database, either the full database or just a single database
13
12
14
13
# ################################
15
14
# Start of procedures/functions #
16
15
# ################################
17
16
18
- funct_check_params () # Function Name
19
- { # Start of the function
20
- if [ ${NARG} -lt 1 ]; then # If the number of arguments is not one, then output a message
17
+ funct_check_params () # Function Name
18
+ { # Start of the function
19
+ if [ ${NARG} -lt 1 ]; then # If the number of arguments is not one, then output a message
21
20
echo " Usage: $0 argument"
22
21
echo " full = Full MySQL Backup"
23
22
echo " db dbname = Single Database backup"
24
- exit 1 # Quit the program
23
+ exit 1 # Quit the program
25
24
elif
26
25
27
26
# If the argument passed is -h or --h then display the following message in the echo statement
@@ -30,27 +29,27 @@ funct_check_params() # Function Name
30
29
echo " Usage: $0 argument"
31
30
echo " full = Full MySQL Backup"
32
31
echo " db dbname = Single Database backup"
33
- exit 1 # Quit the program
34
- fi # End of the if statement
35
- } # End of the function
32
+ exit 1 # Quit the program
33
+ fi # End of the if statement
34
+ } # End of the function
36
35
37
- funct_backup () # Function Name
38
- { # Start of the function
39
- if [ ${choice} = " full" ]; then # If the choice is full, then..
40
- mkdir -p ${BACKUP_DIR} # Make the backup directory
36
+ funct_backup () # Function Name
37
+ { # Start of the function
38
+ if [ ${choice} = " full" ]; then # If the choice is full, then..
39
+ mkdir -p ${BACKUP_DIR} # Make the backup directory
41
40
42
41
# Run the command to backup ALL the databases in MySQL, timestamp the file to the dated folder
43
42
44
43
mysqldump --all-databases | gzip > ${BACKUP_DIR} /full_mysql_backup-` date +%H:%M` .gz
45
- elif # Or
46
- [[ ${choice} = " db" ]]; then # If the choice is db, then..
47
- mkdir -p ${BACKUP_DIR} # Make the backup directory
44
+ elif # Or
45
+ [[ ${choice} = " db" ]]; then # If the choice is db, then..
46
+ mkdir -p ${BACKUP_DIR} # Make the backup directory
48
47
49
48
# Backup just the given database, timestamp the file to the dated folder
50
49
51
50
mysqldump ${dbbkup} | gzip > ${BACKUP_DIR} /${dbbkup} _mysql_backup-` date +%H:%M` .gz
52
51
fi
53
- } # End of the function
52
+ } # End of the function
54
53
55
54
56
55
# ###############
@@ -60,14 +59,14 @@ funct_backup() # Function Name
60
59
# Variable Settings
61
60
62
61
DATE=` date +" %d-%B-%Y" ` ; export DATE # Set the DATE variable, format it as 20-February-2012
63
- choice=$1 # Set the variable choice as the first argument passed
64
- dbbkup=$2 # Set the variable dbbkup as the database to backup
65
- NARG=$# # Set the variable NARG to a number of arguments on the command line
66
-
67
- { # Start of the main program
68
- funct_check_params # Call the function funct_check_params
69
- funct_backup # Call the function funct_backup
70
- } # End of the main program
62
+ choice=$1 # Set the variable choice as the first argument passed
63
+ dbbkup=$2 # Set the variable dbbkup as the database to backup
64
+ NARG=$# # Set the variable NARG to a number of arguments on the command line
65
+
66
+ { # Start of the main program
67
+ funct_check_params # Call the function funct_check_params
68
+ funct_backup # Call the function funct_backup
69
+ } # End of the main program
71
70
72
71
# # End of Script
73
72
0 commit comments