How can I backup home directory and database in sync?

MrCanada

Member
Dec 23, 2017
11
1
3
Canada
cPanel Access Level
Root Administrator
Recently I learned how to use cPanel "Backup" feature. I am using it to back up my Home Directory and my MySQL Database. If I use the option to Download a Full Website Backup (which includes the home directory and the mysql database), will the home directory be synchronized with the mysql database? For example, my database holds references to image files in the home directory. Is it possible for someone to upload an image coincidentally while the backup is happening causing my database and file system to be out of sync? Or is the system completely locked while the backup happens to guarantee the home directory and database stay in sync? Maybe there is another proper way to do this that I am missing? I just want to make sure all of my data is backed up in snyc.
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
462
113
UK
cPanel Access Level
Root Administrator
If your website application has a 'maintenance mode' that you can switch to, that tells users that the site is temporarily off-line - use that - or set up a temporary htaccess redirect to redirect everything to a simple html 'off-line' page.

Either should ensure no user can log in and upload files via the website application.

A user logging into their cPanel or FTP and uploading whilst you are performing the backup may give rise to the situation you describe, and I really don't know if there is any easy way of ensuring that this cannot happen. Conventional advice is to take backups at a time when no-one would likely be doing anything, but with sites serving a global market, this isn't always possible.

If cPanel doesn't lock everything during a backup, perhaps a feature request would be in order.
 
  • Like
Reactions: cPanelMichael

MrCanada

Member
Dec 23, 2017
11
1
3
Canada
cPanel Access Level
Root Administrator
If your website application has a 'maintenance mode' that you can switch to, that tells users that the site is temporarily off-line - use that - or set up a temporary htaccess redirect to redirect everything to a simple html 'off-line' page.

Either should ensure no user can log in and upload files via the website application.

A user logging into their cPanel or FTP and uploading whilst you are performing the backup may give rise to the situation you describe, and I really don't know if there is any easy way of ensuring that this cannot happen. Conventional advice is to take backups at a time when no-one would likely be doing anything, but with sites serving a global market, this isn't always possible.

If cPanel doesn't lock everything during a backup, perhaps a feature request would be in order.

Temporary .htaccess redirect to prevent anyone from uploading during the backup. Didn't even think about that. Thanks!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Temporary .htaccess redirect to prevent anyone from uploading during the backup. Didn't even think about that. Thanks!
Hello,

I'm glad to see that solution works. Note to answer your original question, the website files and MySQL databases are backed up separately during the backup process, so it is possible the data might not be synced if new files are added in time frame between the backup of the website files and databases.

Thank you.