Reading Time: < 1 minute

This is document deals with how to take backup of wordpress(wordpress backup script). The following scrip is daily backup script which deletes old 5 days backup. For wordpress we need to take backup of wordpress contents ( /var/www/html/) and database backup.
If your server crashed you can import these backup to a new machine where all the wordpress dependencies are installed.


Step 1: Create a backup script file.

mkdir /root/backup

vi /root/

Add the following lines

dayago=`(date –date=’05 days ago’ ‘+%Y-%m-%d’)`
todate=$(date +”%Y-%m-%d”)
cd /root/backup
databasepassword= Passw0rd

mkdir $todate

cd $todate

zip -r html$ /var/www/html/
mysqldump -u$databaseuser -p$databasepassword $databasename > database-bk$todate.sql
gzip *.sql
rm -rf ../$dayago


save and exit


Step 2: Change the permission for this file

chmod a+x

Step 3: Configure daily backup using cron.

crontab -e

Add the following line in crontab

0 0 * * * sh /root/

Next restart the cron service

/etc/init.d/cron restart

Thus you have completed the wordpress backup configuration. later you can upload the backuped files to  a FTP server or any other storage location.


© 2018, Techrunnr. All rights reserved.

Questions Answered
Articles Written
Overall Points
Categories: Linux

Prabhin Prabharkaran

He is Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!!


Leave a Reply