Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 1fa4da6

Browse files
committed
Refactored backup-db to support needs of newly added import-db command.
1 parent bec7901 commit 1fa4da6

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

guest/cli/commands/backup-db

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@
22
#
33
# Backup the database to /vagrant/sql/current.sql
44
#
5+
#
6+
# Usage: box import-db {dump_file} [--echo-filename] [--quiet]
7+
#
8+
# Result ==> Imports from /vagrant/sql/{dump_file}.sql
9+
#
10+
# --echo-filename - Echos the backed-up filename
11+
# --quiet - Omits status messages
12+
# --dry-run - Do everything except actually run it
13+
#
514
# Save the prior backup (if exists) to /vagrant/sql/previous.sql
615
# If /vagrant/sql/previous.sql save to /vagrant/sql/previous.2.sql, and so on.
716
#
817

918
bakfile="/vagrant/sql/current.sql"
1019

20+
if [ "true" == $(is_dry_run "$*") ]; then
21+
dryrun=1
22+
else
23+
dryrun=0
24+
fi
25+
1126
#
1227
# Check to see if we need to save a prior backup
1328
#
@@ -22,15 +37,36 @@ if [[ -f "${bakfile}" ]] ; then
2237
# Okay, we can now save the prior backup.
2338
#
2439
echo_if_not_quiet "$*", "=Saving Prior Backup as ${priorfile}..."
25-
cp "${bakfile}" "${priorfile}"
40+
41+
if [ $dryrun -eq 0 ]; then
42+
cp "${bakfile}" "${priorfile}"
43+
fi
2644

2745
fi
2846

2947
echo_if_not_quiet "$*", "=Backing up database to ${bakfile}..."
3048

31-
mkdir -p /vagrant/sql
49+
if [ $dryrun -eq 0 ]; then
50+
51+
mkdir -p /vagrant/sql
52+
53+
mysqldump -u wordpress -pwordpress wordpress > ${bakfile}
3254

33-
mysqldump -u wordpress -pwordpress wordpress > ${bakfile}
55+
result="$?"
56+
57+
if [ "${result}" != "0" ]; then
58+
59+
echo_if_not_quiet "$*", "=mysqldump error (${result})"
60+
return
61+
fi
62+
63+
fi
64+
65+
if [[ "$*" == *"--echo-filename"* ]]; then
66+
67+
echo "${bakfile}"
68+
69+
fi
3470

3571

3672

0 commit comments

Comments
 (0)