-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
devshop-dump-sync.sh
executable file
·65 lines (45 loc) · 2.39 KB
/
devshop-dump-sync.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
set -e
SITE_ALIAS=$1
SITE_DUMP_DIR=/tmp/devshop/$SITE_ALIAS/files
SITE_DUMP_ARCHIVE=/tmp/devshop/$SITE_ALIAS/dumpdb.tar.gz
DRUSH_DUMP_COMMAND="$SITE_ALIAS dumpdb --dump-dir=$SITE_DUMP_DIR --quiet --structure-tables-key=common"
DESTINATION_SERVER=$2
DESTINATION_SITE_ALIAS=$3
COMPRESS_COMMAND="GZIP='--rsyncable' tar czf $SITE_DUMP_ARCHIVE $SITE_DUMP_DIR"
RSYNC_COMMAND="rsync -vz --progress $SITE_DUMP_ARCHIVE $DESTINATION_SERVER:$SITE_DUMP_ARCHIVE"
EXAMPLE_COMMAND="devshop-dump-sync @production aegir@devshop.cloud @mysite.production"
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Hi! I am the devshop-sync tool."
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 You can run me on your server to easily sync your Drupal site's data."
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣"
if [ -z "$SITE_ALIAS" ] || [ -z "$DESTINATION_SERVER" ] || [ -z "$DESTINATION_SITE_ALIAS" ]; then
echo "Please specify a site alias, destination server, and destination site alias. "
echo "ie. 'devshop-dump-sync @production aegir@devshop.cloud @mysite.production'"
exit 1
fi
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 This tool assumes drush and drush syncdb are installed."
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Checking for drush and syncdb..."
drush --version > /dev/null 2>&1
if ! drush --help syncdb > /dev/null 2>&1; then
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 syncdb not found. Installing..."
drush dl syncdb-7.x > /dev/null 2>&1
fi
drush --help syncdb > /dev/null 2>&1
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣"
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Drush and SyncDB tool found!"
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Running command: drush $DRUSH_DUMP_COMMAND..."
if `drush $DRUSH_DUMP_COMMAND`; then
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣"
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Command run successfully. Database files are in $SITE_DUMP_DIR."
fi
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Compressing files: $COMPRESS_COMMAND"
if `$COMPRESS_COMMAND`; then
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Files compressed successfully. Archive available at $SITE_DUMP_ARCHIVE"
fi
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Rsyncing database to remote server $DESTINATION_SERVER..."
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Running Command: $RSYNC_COMMAND";
if `$RSYNC_COMMAND`; then
echo ""
echo "𝗗𝗘𝗩𝗦𝗛𝗢𝗣 Files copied successfully. Archive available at $DESTINATION_SERVER:$SITE_DUMP_ARCHIVE"
fi
echo "TODO: Export the tar on the remote and run drush importdb."