Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

Commit b44fc5c

Browse files
committed
Issue #53: Add a script to dump the database.
1 parent 16124e5 commit b44fc5c

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
echo "Dumping databases to Parrot database folder."
4+
echo ""
5+
echo "This will overwrite any existing data."
6+
7+
BACKUP_DIR="/vagrant_databases"
8+
MYSQL_USER="root"
9+
MYSQL=/usr/bin/mysql
10+
MYSQL_PASSWORD="root"
11+
MYSQLDUMP=/usr/bin/mysqldump
12+
13+
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(parrot|Database|information_schema|mysql)"`
14+
15+
for db in $databases; do
16+
echo "Dumping $db to $BACKUP_DIR/$db.sql"
17+
$MYSQLDUMP --force --user=$MYSQL_USER -p$MYSQL_PASSWORD --quick --single-transaction --databases $db > "$BACKUP_DIR/$db.sql"
18+
done
19+
20+
echo "All databases exported."

modules/parrot_mysql/manifests/init.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
# Puppet magically turns our array into lots of resources.
4141
parrot_mysql::database_import { $db_names: }
4242

43-
43+
file {'/var/parrot-dump-databases.sh':
44+
ensure => file,
45+
source => 'puppet:///parrot_mysql/parrot-dump-databases.sh',
46+
mode => 755,
47+
}
4448

4549
}

scripts/dump-databases.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
# Change to the directory that this script is stored in.
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
cd $DIR
7+
8+
# Ensure that the VM is up.
9+
vagrant up
10+
11+
# And run the script in the VM.
12+
vagrant ssh --command '/var/parrot-dump-databases.sh'

0 commit comments

Comments
 (0)