Skip to content

Instantly share code, notes, and snippets.

@rdlmda
Last active August 23, 2016 21:00
Show Gist options
  • Select an option

  • Save rdlmda/04e67077dab15502dce8b7c9f21f8601 to your computer and use it in GitHub Desktop.

Select an option

Save rdlmda/04e67077dab15502dce8b7c9f21f8601 to your computer and use it in GitHub Desktop.

Revisions

  1. Rudá Almeida revised this gist Aug 23, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion remote-export-single-wpmu-site.sh
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,6 @@ scp /root/[filename].tar.bz2 webserver:~/backup/database/[filename]-${now}.tar.
    rm /root/[filename].sql
    rm /root/[filename].tar.bz2

    rsync -varz /var/www/[wp-multisite-path]/wp-content/uploads/sites/[site-numeric-id]/ webserver:~/backup/uploads
    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
  2. Rudá Almeida created this gist Aug 23, 2016.
    24 changes: 24 additions & 0 deletions remote-export-single-wpmu-site.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/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/[site-numeric-id]/ 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