0

I have a question about the cron Job command.

I want to load a back-up of my wordpress site and the mysql database back-up daily. So it restores all settings to the back-ups of my wordpress site and the mysql database.

But I can't find the all the possible command that i can use for cron jobs. Or do I just type the path of where the back-up files are placed?

I don't use php code because I am using direct admin.

Hope to hear from you soon!

Jeroen
  • 3
  • 2
  • Possible duplicate of [PHP regular backup of mysql data](http://stackoverflow.com/questions/38916163/php-regular-backup-of-mysql-data) – e4c5 Aug 19 '16 at 04:04

1 Answers1

1

cron can fire all kinds of stuff. Generally everything that is executable. I would suggest writing a backup bash script or something.

  1. dump your database using mysqldump.
  2. backup your site using rsync or git.

Also: you do not want to backup your stuff on your production-machine. If it breaks everything is gone!

Put your backup cronjob in /etc/cron.d/webbackup with the file-content:

# m h dom mon dow user  command
25 6    * * *   root    path/to/your/backupscript.sh
#

and then write a backupscript.sh like this (this is pseudocode NOT an actual script)

file: backupscript.sh

#!/bin/bash
path/to/mysqldump.sh
rsync -avz /your/website/ username@backupserver:/path/to/backupfolder/
rsync -avz /your/mysqldump/folder/ username@backupserver:/path/to/mysqlbackupfolder/

file: mysqldump.sh (this is not mine but I modified it)

#!/bin/bash
# TARGET: Backup-Ziel
# IGNORE: Liste zu ignorierender Datenbanken (durch | getrennt)
# CONF: MySQL Config-Datei, welche die Zugangsdaten enthaelt
TARGET=/var/backups/mysql
IGNORE="phpmyadmin|mysql|information_schema|performance_schema|test"
CONF=/etc/mysql/debian.cnf
if [ ! -r $CONF ]; then /usr/bin/logger "$0 - auf $CONF konnte nicht zugegriffen
 werden"; exit 1; fi
if [ ! -d $TARGET ] || [ ! -w $TARGET ]; then /usr/bin/logger "$0 - Backup-Verze
ichnis nicht beschreibbar"; exit 1; fi

DBS="$(/usr/bin/mysql --defaults-extra-file=$CONF -Bse 'show databases' | /bin/g
rep -Ev $IGNORE)"
NOW=$(date +"%Y-%m-%d")

for DB in $DBS; do
    /usr/bin/mysqldump --defaults-extra-file=$CONF --skip-extended-insert --skip
-comments $DB > $TARGET/$DB.sql
done

if [ -x /usr/bin/git ] && [ -d ${TARGET}/.bzr/branch ]; then
  cd $TARGET
  /usr/bin/git add -A
  /usr/bin/git commit -m "$NOW"
else
  /usr/bin/logger "$0 - bzr nicht verfuegbar oder Backup-Ziel nicht unter Versio
nskontrolle"
fi

/usr/bin/logger "$0 - Backup von $NOW erfolgreich durchgefuehrt"
exit 0

You will need to look into ssh and ssh-copy-id for this. There are better solutions like git etc. but this might be something to get you started.

I hope that helped a little...

Christian
  • 113
  • 7
  • Hello Christian, Thanks for your reply. But can i load a back-up or files without using php code? – Jeroen Dec 23 '14 at 13:40
  • Do you mean how to restore a backup? If so you will need to do the two things in reverse: 1. restore your Databases from mysql-dump 2. restore your file system from rsync – Christian Jan 05 '15 at 07:36
  • No, i want to load the back up. So the reverse thing of restore. I want to make a back-up from let's say wordpress site 1. All the information, designs, database, sql etc. All those info i want to load daily on the wordpress site 2. So all the designs that i have changed before will be restored. Hope that this is clear, because my english isn't the best.. – Jeroen Jan 05 '15 at 15:02
  • So you want to mirror the site and have them both running? Are site1 and site2 on the same Server? if so you will need to duplicate the database and connection which is a bit more involeved, adn copy your code to the secound webspace. – Christian Jan 21 '15 at 09:01