I'm working on a script which will upload all the zpanel backups to my Amazon S3 account. It works if I don't use the zpanel backups and create and upload backups created by me using CronJob.
The reason why I cannot upload the zpanel backup is I cannot figure out a way to reach the "backups" directory using php opendir function.
I know the absolute path of the backups folder though. And as it seems, this absolute path won't work with opendir()
I've used : opendir('var/zpanel/hostdata/my_username/backups/')
And it won't work. Now if I want to use the relative path, I cannot reach there either.
So, is there a way that I can move the zPanel Backups directory somewhere inside the public_html folder? Or, a web URL that can reach the backups folder? Ajaxplorer can reach there, why I cannot?
If none is possible, I'll greatly appreciate if someone can teach me a way to create backups exactly like zPanel (all DB + everything inside public_html folder).
The code looks like this
require_once('S3.php');
// Enter your amazon s3 creadentials
$s3 = new S3('xxxxx', 'xxxxx');
if ($handle = opendir('var/zpanel/hostdata/my_username/backups/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
//echo "okay";
echo $file; exit;
if ($s3->putObjectFile("backups/$file", "my_basket", "$file", S3::ACL_PUBLIC_READ)) {
echo "<strong>We successfully uploaded your file.<br /></strong>";
//this will delete the file from your server after upload
//if (file_exists($baseurl . '/' . $file)) { unlink ($baseurl . '/' . $file); }
}else{
echo "<strong>Something went wrong while uploading your file... sorry.</strong>";
}
}else{
echo "No file found here ".$root;
}
}
closedir($handle);
}
Thanks a lot in advance!