1

This is a basic question.. I am trying to write a very simple script to backup my wordpress database every hour..

#!/bin/sh
#
# This script do an hourly backup of WordPress DB

# Set global parameters
WPROOT=/home/mydomain/public_html
WPBKUPS=/usr/home/mydomain/db_backups
SITEURL=`wp option get siteurl | awk -F/ '{print $3}'`
BKNAME="$WPBKUPS/`date +%Y-%m-%d.%H%M`-$SITEURL"

# change directory
#cd $WPROOT
#cd /usr/local/www/production/httpdocs/wpsite
wp db export --allow-root - | gzip -9 > $BKNAME.sql.gz

# Stop build-up of loads of older files with exec rm \o/
find "$WPBKUPS" -mtime +1 -exec rm {} \;

Question 1: should I be using the option --add-drop-table? what is the difference with my code

Question 2: at the moment the script reside insite the wproot.. how can I change the script so that the script is not in the public facing directory?

Thank you

Frederic
  • 23
  • 6

1 Answers1

1

Question 1: --add-drop-table it will add Add DROP TABLE statement before each CREATE TABLE statement. While restoring it drops the table is already exists.

You can find more about this here Link

Question 2: mysqldump –-user [user name] –-password=[password] [database name] > [dump file]

for example: /usr/bin/mysqldump --user="root" --password="root" "wp_db" > wp_db.sql

add this command into a script file then store it outside of WordPress root.

Make the script executable from a terminal,

chmod +x /path/to/yourscript.sh

Open your personal crontab as

EDITOR=gedit crontab -e

and append the following line in it to run your script every hour.

0 */1 * * *  /path/to/yourscript.sh 
Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71