Skip to content

Commit a1f11c7

Browse files
committed
Backup MySQL database, either the full database or just a single database
1 parent fa34166 commit a1f11c7

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

Diff for: mysql_backup.sh

+29-30
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
#!/bin/bash
22

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
78

89
# Modifications :
910

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
1312

1413
#################################
1514
# Start of procedures/functions #
1615
#################################
1716

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
2120
echo "Usage: $0 argument"
2221
echo "full = Full MySQL Backup"
2322
echo "db dbname = Single Database backup"
24-
exit 1 # Quit the program
23+
exit 1 # Quit the program
2524
elif
2625

2726
# 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
3029
echo "Usage: $0 argument"
3130
echo "full = Full MySQL Backup"
3231
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
3635

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
4140

4241
# Run the command to backup ALL the databases in MySQL, timestamp the file to the dated folder
4342

4443
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
4847

4948
# Backup just the given database, timestamp the file to the dated folder
5049

5150
mysqldump ${dbbkup} | gzip > ${BACKUP_DIR}/${dbbkup}_mysql_backup-`date +%H:%M`.gz
5251
fi
53-
} # End of the function
52+
} # End of the function
5453

5554

5655
################
@@ -60,14 +59,14 @@ funct_backup() # Function Name
6059
# Variable Settings
6160

6261
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
7170

7271
## End of Script
7372

0 commit comments

Comments
 (0)