Join the community today
Become a Member

Sysadmin Wordpress Backup

Discussion in 'System Administration' started by fabianski, May 9, 2019.

  1. fabianski

    fabianski Member

    102
    14
    18
    Feb 20, 2019
    Ratings:
    +36
    Local Time:
    8:05 PM
    I'm looking for an alternative to automatically back up wordpress to google drive without any plugin and found this script in bash.


    wpbullet/wp-cli-backups-cloud-storage
    https://guides.wp-bullet.com/automatically-back-wordpress-google-drive-wp-cli-bash-script/

    It works great still, the problem is that the database backup is generated for every folder or file that is in the directory.

    Example: in /home/nginx/domains/DOMAIN.COM/public there are several folders, wp-content, wp-admin, wp-includes, ...
    A database backup is created for each of them, incluse for files such as wp-config.php, wp-login.php, ...
    Look: https://prnt.sc/nm1wt2 GDrive: http://prntscr.com/nm1xze

    I set the location of the wordpress installation so
    Code:
    #path to WordPress installations, no trailing slash
    SITESTORE="/home/nginx/domains/DOMAIN.COM/public"
    I do not know if this is an incompatibility with the centminmod or if it is some error of the script itself.

    Any help will be welcome.
    Thank you!
     
  2. fabianski

    fabianski Member

    102
    14
    18
    Feb 20, 2019
    Ratings:
    +36
    Local Time:
    8:05 PM
    I tried adding the grep command to some folder to try to limit these various database backups but this does not seem to work very well.

    The compressed database files sent to google drive are only 20kb and have nothing inside them(http://prntscr.com/nm2gem).
    This error only happens if it is backed up via CRON because when I run the command manually (/bin/bash /home/nginx/domains/DOMAIN.COM/cronjobs/db-backup.sh) it works fine.

    My cron:
    25 1 * * * /bin/bash /home/nginx/domains/DOMAIN.COM/cronjobs/db-backup.sh
     
    Last edited: May 9, 2019
  3. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    9:05 AM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    here's a little hint/tip, the script has defined
    Code (Text):
    SITESTORE="/var/www"
    #create array of sites based on folder names
    SITELIST=($(ls -d $SITESTORE/* | awk -F '/' '{print $NF}'))
    

    on some non-centminmod setups /var/www is the upper parent directory for each apache vhost site like centmin mod's /home/nginx/domains. So if you have site called domain.com:
    • on non-centmin mod setup, it maybe located at /var/www/domain.com
    • on centmin mod setup, it would be located at /home/nginx/domains/domain.com as per outline at https://centminmod.com/configfiles.html
    so what that SITELIST is doing is creating an array of sites based on folder names i.e. /var/www/domain.com, /var/www/domain2.com would have SITELIST value = 'domain.com domain2.com' so it treats each folder as a site backup and that is why you see a backup created the way you do as script is treating every folder under /home/nginx/domains/domain.com as a separate site

    so one workaround is define SITESTORE correctly as /home/nginx/domains which is parent directory which has each directory name = a nginx vhost site domain name.
    Code (Text):
    SITESTORE="/home/nginx/domains"
    

    though from what i can see, script will backup everything each /home/nginx/domains/domain.com directory, including the backup directory at /home/nginx/domains/domain.com/backup which you may want to exclude if you have other backup scripts saving backups to /home/nginx/domains/domain.com/backup as it would be doing duplicate backups.

    Though the script has no error checking and validation of the backup processes and incorrectly forces --single-transaction option for mysqldump regardless of whether you have non-innodb tables = for non-innodb tables you may not get a safe backup data integrity wise. FYI, proper error checking/validation and conditional mysqldump options and character set determination is built into my dbbackup.sh database backup script for Centmin Mod Premium members ;) :)

    Also chown routine in that script will break sites on Centmin Mod due to files/directories owned by nginx user/group and not www-data. Also chmod recursive commands may break your sites where you have specifically set writable directories with 777 permissions as they would be recursively changed to 755 by that script.

    Just my AUD$0.02, rest is up to you and/or other members to chime in :)
     
  4. fabianski

    fabianski Member

    102
    14
    18
    Feb 20, 2019
    Ratings:
    +36
    Local Time:
    8:05 PM
    I really wanted to support the development of cmm with some donation and become premium, at the moment I do not have the conditions for this, so I am using this alternative.

    Apparently the problem was script permission, I switched to 744 and now it's working.
     
  5. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    9:05 AM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    yeah totally understand

    though strange it required 744 permissions