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/backup.sh

Add the following lines

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

mkdir $todate

cd $todate

zip -r html$todate.zip /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 backup.sh

Step 3: Configure daily backup using cron.

crontab -e

Add the following line in crontab

0 0 * * * sh /root/backup.sh

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.

#1
#2
#3
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!!

0 Comments

Leave a Reply

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.