Using PHP to create file backups on cloud storage

Hey everyone, I’m trying to set up an automatic backup system for my website files and database using PHP. I’ve got everything hosted on a web server and I’m aiming to store the backups on a cloud storage service.

I found a tutorial online and followed the steps. I’ve set up the API client, got my credentials, and tweaked the settings file with my info. The script is supposed to create a compressed folder with my site files and another one for the database, then upload both to the cloud.

Here’s the thing though - when I run the script, it creates two folders alright, but the one for the website files is empty! The database backup seems fine.

I’ve double-checked my directory settings:

$homedir = '/home/myuser/public_html/';
$sitedir = 'public_html/';

Any ideas why the site files aren’t being included in the backup? I’m scratching my head here. Thanks for any help!

I’ve had a similar issue before, and it turned out to be related to how I was specifying the directories. Try using absolute paths instead of relative ones. Replace your current directory settings with:

$homedir = '/home/myuser/public_html/';
$sitedir = '/home/myuser/public_html/';

This ensures the script knows exactly where to look for files. Also, make sure you’re using the correct function to copy files recursively. The PHP copy() function won’t work for directories. Instead, you might need to implement a custom recursive function or use something like RecursiveDirectoryIterator.

Lastly, check your PHP memory limit. If you’re dealing with a large site, you might be hitting the memory ceiling when trying to compress everything. You can increase it in your php.ini file if needed. Good luck!

Have you verified the script is actually traversing the directory structure correctly? It’s possible the issue lies in how the script is reading and compressing files. You might want to add some debug logging to see which files and directories are being processed. Also, ensure there’s enough disk space for the compressed archive. Sometimes, silent failures occur due to space constraints. Lastly, check if there are any file size or type restrictions in your compression method that might be excluding certain files. If all else fails, consider using a established backup solution like Duplicator or UpdraftPlus for more reliable results.

hey emma, sounds like a permission issue. check if ur script has read access to the site files. try running it with elevated privileges or adjust file perms. also, double-check the $sitedir path - it might be redundant if $homedir already includes ‘public_html/’. hope this helps!