-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackwpupfile.yaml
More file actions
88 lines (69 loc) · 3.73 KB
/
Copy pathbackwpupfile.yaml
File metadata and controls
88 lines (69 loc) · 3.73 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# ============ OUTDATED FILE ======================
# This project was moved to:
# https://github.com/mandrasch/ddev-pull-wp-scripts
# Import a backwup .zip-file
# !! MAKE SURE YOU GOT DDEV VERSION >= 1.18.2 !!
# (Otherwise overriding files_import_command won't work)
# This will import a backwpup .zip-file into the DDEV project
# Plugin: https://wordpress.org/plugins/backwpup/
# The script will automatically replace (migrate) the URLs in database.
# The import only overrides files which are not tracked by git
# using the .gitignore file.
# TODO: get filename of .zip from cli argument - how? would be easier?
environment_variables:
backupfile: backup.zip # needs to be in docroot (your project folder)
# This unzips the sql file from backup and generates a .sql.gz file,
# which DDEV imports automatically (via standard db_import_command)
# (This script also determines name of database via bash command,
# thanks to https://stackoverflow.com/a/63494305/809939)
# The database url replace-search will be done later in files_import_command
db_pull_command:
command: |
# set -x # You can enable bash debugging output by uncommenting
set -eu -o pipefail
pushd "/var/www/html/${DDEV_DOCROOT}" >/dev/null
mkdir -p /var/www/html/.ddev/.downloads/db
echo "Unzipping wp-config.php to figure out the database name ..."
unzip -j "${backupfile}" "wp-config.php" -d /var/www/html/.ddev/.downloads/db
# TODO: save DB_NAME as var temporarily in bash?
pushd /var/www/html/.ddev/.downloads/db >/dev/null
echo "Unzipping the <DB_NAME>.sql file from backwpup zip file ..."
unzip -j "/var/www/html/${DDEV_DOCROOT}${backupfile}" "$(sed -n "s/define( *'DB_NAME', *'\([^']*\)'.*/\1/p" wp-config.php).sql" -d .
echo "Renaming the <DB_NAME>.sql file to db.sql ..."
mv $(sed -n "s/define( *'DB_NAME', *'\([^']*\)'.*/\1/p" wp-config.php).sql db.sql
echo "Gzipping the .sql file to let DDEV handle the db import ..."
gzip -cvf /var/www/html/.ddev/.downloads/db/db.sql > /var/www/html/.ddev/.downloads/db.sql.gz
service: web
files_pull_command:
command: |
# set -x # You can enable bash debugging output by uncommenting
set -eu -o pipefail
pushd /var/www/html/${DDEV_DOCROOT} >/dev/null
echo "Unzipping the backwpup .zip file to .ddev/.downloads/files ..."
unzip -q "${backupfile}" -d /var/www/html/.ddev/.downloads/files
# echo "Content of .ddev/.downloads/files after sync:"
# ls -l /var/www/html/.ddev/.downloads/files
service: web
# Final steps:
# a) Overwrite files in docroot, but without overwriting git-tracked files
# using .gitignore file
# b) Replace live site url (determined from backup) with DDEV_PRIMARY_URL
# (<your-project>.ddev.site) with help of WP-CLI
# TODO: re-generate permalinks?
# TODO: update upload_path?
files_import_command:
command: |
# set -x # You can enable bash debugging output by uncommenting
set -eu -o pipefail
pushd "/var/www/html/${DDEV_DOCROOT}" >/dev/null
echo "Rsyncing all files and folders which are not tracked by git to docroot ..."
# add -v for debug purposes
rsync -azh --stats --include-from='.gitignore' --exclude='*' /var/www/html/.ddev/.downloads/files/ .
echo "Adjusting wp-config for DDEV (database connection) ..."
wp config set DB_NAME "db" && wp config set DB_USER "db" && wp config set DB_PASSWORD "db" && wp config set DB_HOST "db"
echo "Replacing the old URL ($(wp option get siteurl)) in database with DDEV local url (${DDEV_PRIMARY_URL})..."
wp search-replace $(wp option get siteurl) "${DDEV_PRIMARY_URL}"
# echo "Deleting config path for WP Super Cache (if installed) ..."
# wp config delete WPCACHEHOME
echo "All set, have fun! Run 'ddev launch' to open your site."
service: web