Last active
August 23, 2016 21:00
-
-
Save rdlmda/04e67077dab15502dce8b7c9f21f8601 to your computer and use it in GitHub Desktop.
Export and backup a single site from a WordPress Multisite install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # A função deste script é realizar o backup do banco de dados e das pastas de um site isolado | |
| # de uma instalação WordPress Multisite, independente dos outros sites presentes na mesma | |
| # instalação. Para isso é utilizado o "wp db export", bem como o rsync das pastas com a ID | |
| # do site (hardcoded, no futuro melhorar isso). | |
| # | |
| # Este script deve ser colocado na máquina que hospeda o multisite e executado | |
| # periodicamente via cron. A máquina destino deve possuir as credenciais de acesso. | |
| # Prevents commands not being located when running in cron | |
| export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | |
| now=$(date +"%Y-%m-%d_%H-%M-%S") | |
| wp db export /root/[filename].sql --path=/var/www/[wp-multisite-path] --tables=$(wp db tables --path=/var/www/[wp-multisite-path] --scope=blog --url=[site url] --format=csv --allow-root) --allow-root | |
| tar cvjf [filename].tar.bz2 [filename].sql | |
| scp /root/[filename].tar.bz2 webserver:~/backup/database/[filename]-${now}.tar.bz2 | |
| rm /root/[filename].sql | |
| rm /root/[filename].tar.bz2 | |
| rsync -varz /var/www/[wp-multisite-path]/wp-content/uploads/sites/$(wp site list --domain=[domain] --path=/var/www/[wp-multisite-path] --format=csv --allow-root | sed 1d)/ webserver:~/backup/uploads | |
| rsync -varz /var/www/[wp-multisite-path]/wp-content/plugins/ webserver:~/backup/plugins | |
| rsync -varz /var/www/[wp-multisite-path]/wp-content/themes/[theme-path]/ webserver:~/backup/tema |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wp site list --domain=[domain]only works because I use a plugin that allows each sub-site to have its own domain.See http://wp-cli.org/commands/site/list/