• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

How to make a backup of website files & MySQL databases cron task

W

willgnosis

Guest
OK.. I wanted to write this because it has just taken me about 2 weeks of searching the net and trial and error to finally get a backup how i wanted.

In case you didn't know.. when you use the Plesk Backup Scheduer, it creates a file that apparently only Linux can unpack and is basically useless if you want to ever open the files on a pc.

So if, like me, you just want to be able to make a regular backup of your webisite files and it's databases you can do it like this:

First:

log into FTP using root user and go to the path /
Make a new folder called backup
make sure it has permissions set to 777
(most FTP programs you can right click the folder and choose 'file attributes' and set it to 777)

Next:

Login to Plesk
> Click Server on the left panel
> Click Scheduled Tasks
> Select the Root user
> Add New Task

Minute: 01 ( this means 01 minutes past the hour)
Hour: 02 (This means 02:00 AM)
Day of Month: * (This means every day)
Month: * (This means every Month)
Day of the Week : * ( This means every day)

Then for the command:

mysqldump --user=admin --password=youradminpassword --all-databases > /backup/mysqlall-`/bin/date +\%Y\%m\%d`.sql

That's for the database backup - This backs up ALL MySQL databases - for every website.

Now repeat and make another Scheduled task to backup all the web files for a certain domain:

You need this command:

tar -cvzf /backup/mywebsite.com-backup-`/bin/date +\%Y\%m\%d`.tar /var/www/vhosts/mywebsite.com/httpdocs

and finally

make a 3rd task that runs this command:

find /backup -mtime +5 -exec rm {} \;

This will delete any files older than 5 days.

Voila! A PROPER backup!

Oh yeah... if you try and put these together into a script file and try to cron run that... it doesn't work. no idea why.

This would have saved me 2 weeks!!!!
So Please don't remove it!

Will
 
Hi willgnosis,

When saving all databases in one dump file, how is the process of restoring only one database from that dump file?
 
Thank you will for sharing this. it helped me a lot and saved my time.
 
First:

log into FTP using root user and go to the path /
Make a new folder called backup
make sure it has permissions set to 777
(most FTP programs you can right click the folder and choose 'file attributes' and set it to 777)

Next:

Login to Plesk
> Click Server on the left panel
> Click Scheduled Tasks
> Select the Root user
> Add New Task

Minute: 01 ( this means 01 minutes past the hour)
Hour: 02 (This means 02:00 AM)
Day of Month: * (This means every day)
Month: * (This means every Month)
Day of the Week : * ( This means every day)

Then for the command:

mysqldump --user=admin --password=youradminpassword --all-databases > /backup/mysqlall-`/bin/date +\%Y\%m\%d`.sql

That's for the database backup - This backs up ALL MySQL databases - for every website.

Now repeat and make another Scheduled task to backup all the web files for a certain domain:

You need this command:

tar -cvzf /backup/mywebsite.com-backup-`/bin/date +\%Y\%m\%d`.tar /var/www/vhosts/mywebsite.com/httpdocs

and finally

make a 3rd task that runs this command:

find /backup -mtime +5 -exec rm {} \;

This will delete any files older than 5 days.

Ok, I cant seem to get any of the above to work, also I cant find where I check to see if the log error is being emailed to me!!

My site got hacked last week and I would really like to get this working so I have a contingency plan if it happens again..

Any help would be much appreciated!!
 
Really, no help what so ever!!

I would really appreciate some to fix the log error not being emailed to me!!
 
here is the trick, put /var/www/vhosts/mywebsite.com path before every path:


mysqldump --user=admin --password=youradminpassword --all-databases > /var/www/vhosts/mywebsite.com/backup/mysqlall-`/bin/date +\%Y\%m\%d`.sql

tar -cvzf /backup/mywebsite.com-backup-`/bin/date +\%Y\%m\%d`.tar /var/www/vhosts/mywebsite.com/httpdocs

/bin/find /var/www/vhosts/mywebsite.com/backup -mtime +5 -exec rm {} \;


this works for me
 
Last edited:
Back
Top