Skip to content

Commit

Permalink
Backport snapshot export/import scripts from D10 image
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobSanford committed May 31, 2024
1 parent bea03d5 commit 4296701
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
15 changes: 15 additions & 0 deletions build/scripts/exportContent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

if [ $# -ne 1 ];then
echo "No target location specified."
exit 1
fi

mkdir -p "$1"

OUTPUT_FILE="$1/db.sql"
/scripts/clearDrupalCache.sh > /dev/null 2>&1
/scripts/sqlDump.sh "$OUTPUT_FILE"
gzip -f "$OUTPUT_FILE"
echo "$OUTPUT_FILE.gz"
17 changes: 17 additions & 0 deletions build/scripts/exportData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh
set -e

if [ $# -ne 1 ];then
echo "No target location specified, generating random location."
HASH=$(echo $RANDOM | md5sum | head -c 20; echo)
BASE_PATH='/data-export'
EXPORT_PATH="$BASE_PATH/$HASH"
mkdir -p "$EXPORT_PATH"
chown $NGINX_RUN_USER:$NGINX_RUN_GROUP $EXPORT_PATH
else
EXPORT_PATH="$1"
fi

# Export Content
/scripts/exportContent.sh "$EXPORT_PATH"
/scripts/exportFiles.sh "$EXPORT_PATH"
15 changes: 15 additions & 0 deletions build/scripts/exportFiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

if [ $# -ne 1 ];then
echo "No target location specified."
exit 1
fi

mkdir -p "$1"

OUTPUT_FILE="$1/files.tar.gz"
/scripts/clearDrupalCache.sh > /dev/null 2>&1
cd "$DRUPAL_ROOT/sites/default/files"
tar -cvpzf "$1/files.tar.gz" --exclude=*.css --exclude=*.css.gz --exclude=*.js --exclude=*.js.gz --exclude=./php --exclude=./styles . > /dev/null 2>&1
echo "$OUTPUT_FILE"
18 changes: 18 additions & 0 deletions build/scripts/importContent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh
set -e

if [ $# -ne 1 ];then
echo "No database file specified!"
exit 1
elif [ ! -f "$1" ] ; then
echo "$1 does not exist!"
exit 1
fi

# Import the content.
EXTRACTED_PATH=$(echo $1 | rev | cut -f 2- -d '.' | rev)
EXTRACTED_FILE=$(basename "$EXTRACTED_PATH")
gunzip -c "$1" > "/tmp/$EXTRACTED_FILE"
echo "Importing $EXTRACTED_FILE"
sh -c "$DRUSH sql-cli < /tmp/$EXTRACTED_FILE"
$DRUSH cr
20 changes: 20 additions & 0 deletions build/scripts/importData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env sh
set -e

if [ $# -ne 1 ]; then
echo "No import location specified!"
exit 1
elif [ ! -f "$1/db.sql.gz" ] ; then
echo "$1/db.sql.gz does not exist!"
exit 1
fi

# Import Content.
/scripts/importContent.sh "$1/db.sql.gz"

# (Optionally) Import Files.
if [ -f "$1/files.tar.gz" ] ; then
/scripts/importFiles.sh "$1/files.tar.gz"
fi

echo 'Success!'
18 changes: 18 additions & 0 deletions build/scripts/importFiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh
# Note! No private filesystem support.
set -e

if [ $# -ne 1 ];then
echo "No public filesystem archive specified!"
exit 1
elif [ ! -f "$1" ] ; then
echo "$1 does not exist!"
exit 1
fi

# Import the filesystem archive to the public filesystem.
tar -tzf $1 >/dev/null # Check if the archive is valid.
rm -rf "$DRUPAL_ROOT/sites/default/files/*"
tar -xzf $1 --directory "$DRUPAL_ROOT/sites/default/files/"
/scripts/pre-init.d/71_set_public_file_permissions.sh
/scripts/pre-init.d/72_secure_filesystems.sh
9 changes: 9 additions & 0 deletions build/scripts/sqlDump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh
set -e

if [ $# -ne 1 ];then
echo "No target specified."
exit 1
fi

$DRUSH sql-dump --extra-dump=--no-tablespaces --structure-tables-list="accesslog,batch,cache,cache_*,ctools_css_cache,ctools_object_cache,flood,search_*,history,queue,semaphore,sessions,watchdog" --result-file=$1

0 comments on commit 4296701

Please sign in to comment.