Help Creating a Backup Script
Moderator: General Moderators
-
Dirge of Cerberus
- Forum Commoner
- Posts: 38
- Joined: Mon Nov 20, 2006 9:01 pm
Help Creating a Backup Script
I need help creating a backup script. I need to know how to select every file, including subdirectory and etcetera, and FTP it to another server, where it would be stored by date, like 'SERVER_ROOT/Backup-01-09-07-6 15 PM/sitebackupfilesgohere'.
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
Have you searched the manual for PHP's FTP functions or file/directory functions?
-
Dirge of Cerberus
- Forum Commoner
- Posts: 38
- Joined: Mon Nov 20, 2006 9:01 pm
Hmm... Okay. I've cobbled together some of the code. I just need to know how to select all files to transfer.
Code: Select all
<?php
#FTP CONNECTION CODE
$dir = date('l dS \of F Y h:i:s A');
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to create the directory $dir
if (ftp_mkdir($conn_id, $dir)) {
echo "successfully created $dir. Moving onto Backup...<br>\n";
} else {
echo "There was a problem while creating $dir. Exiting...\n";
exit();
}
# FTP File Transfer Code here...
// close the connection
ftp_close($conn_id);
?>- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
-
Dirge of Cerberus
- Forum Commoner
- Posts: 38
- Joined: Mon Nov 20, 2006 9:01 pm
aaronhall:
scandir() isn't supported on my server.
ole:
I am not the root, so i doubt I can rsync.
scandir() isn't supported on my server.
Code: Select all
Fatal error: Call to undefined function: scandir() in /home/content/a/n/i/animestome/html/admin/scandirtest.php on line 3I am not the root, so i doubt I can rsync.
-
Dirge of Cerberus
- Forum Commoner
- Posts: 38
- Joined: Mon Nov 20, 2006 9:01 pm
Code: Select all
<?php
// FTP Connection info went here.
$ftpdir = date('l dS \of F Y h:i:s A');
echo $ftpdir;
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to create the directory $dir
if (ftp_mkdir($conn_id, $ftpdir)) {
echo "successfully created the directory $ftpdir. Moving onto Backup...<br>\n";
} else {
echo "There was a problem while creating the directory $ftpdir. Exiting...\n";
exit();
}
# FTP File Transfer Code here...
$dir = "/..";
if ($handle = opendir('/..')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$localfile = $file;
$remote_file = "$ftpdir/$file";
// upload a file
if (ftp_put($conn_id, $remote_file, $localfile, FTP_ASCII)) {
echo "Successfully uploaded <font color=green><b>$localfile</b></color><br>\n";
} else {
echo "There was a problem while uploading <font color=red><b>$localfile</b></font><br>\n";
}
}
}
closedir($handle);
}
// close the connection
ftp_close($conn_id);
?>-
Dirge of Cerberus
- Forum Commoner
- Posts: 38
- Joined: Mon Nov 20, 2006 9:01 pm
-
Dirge of Cerberus
- Forum Commoner
- Posts: 38
- Joined: Mon Nov 20, 2006 9:01 pm
Code: Select all
<?php
$ftp_server = "host";
$ftp_user_name = "**********";
$ftp_user_pass = "******";
$ftpdir = date('l dS \of F Y h:i:s A');
echo $ftpdir;
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to create the directory $dir
if (ftp_mkdir($conn_id, $ftpdir)) {
echo "successfully created the directory $ftpdir. Moving onto Backup...<br>\n";
} else {
echo "There was a problem while creating the directory $ftpdir. Exiting...\n";
exit();
}
# FTP File Transfer Code here...
$dir = "/..";
if ($handle = opendir('/..')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$localfile = $file;
$remote_file = "$ftpdir/$file";
// upload a file
if (ftp_put($conn_id, $remote_file, $localfile, FTP_ASCII)) {
echo "Successfully uploaded <font color=green><b>$localfile</b></color><br>\n";
} else {
echo "There was a problem while uploading <font color=red><b>$localfile</b></font><br>\n";
}
}
}
closedir($handle);
}
// close the connection
ftp_close($conn_id);
?>- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
What is the output of the script and what errors are being thrown, if any? What directory is opendir('/..') trying to reference?
Last edited by aaronhall on Tue Jan 09, 2007 10:21 pm, edited 1 time in total.