backup-website-via-ftp

Gesponsorde koppelingen

PHP script bestanden

  1. backup-website-via-ftp

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?
//Backup Script
//
// Copyright DNSSniffer.com

//Settings Begin -- You can edit the values below --
//Folder you want to backup.

$localpath = "/var/www/domein.nl/";
//Folder where you placed this file.
$backuppath = "/var/www/backup/domein.nl/";
//Folder on the ftp server.
$ftppath = "domein.nl";
//Ftp hostname
$ftp_server = "ftp.jouwftpserver.nl";
//Ftp username
$ftp_user_name = "gebruikersnaam";
//Ftp Password
$ftp_user_pass = "wachtwoord";
//Settings End -- Do not edit the settings below --

//Global Settings --Do Not Edit--

$fullday = date("l");
$dayofmonth = date("d");
$date = date("m-d-Y");
$dailydstfile = "$ftppath/$fullday/$fullday.tgz";
$dailysrcfile = "$backuppath$fullday.tgz";
$monthdstfile = "$ftppath/Monthly/$date.tgz";
$monthsrcfile = "$backuppath$fullday.tgz";

//Tar the the folder contents
exec("tar czPf $fullday.tgz $localpath");

//Open the connection
$conn_id = ftp_connect($ftp_server);

//Login in the ftp server
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

//Check the connection
if ((!$conn_id) || (!$login_result)) {
            echo"FAIL. Connection Error \n";
        exit;
    }
else {
            echo"OK. Connected to $ftp_server \n";
}


//Check The Main Directory
$contentsfolder = ftp_nlist($conn_id, ".");
if (in_array("./$ftppath", $contentsfolder)) {
    echo "OK. Directory $ftppath exists. \n";
}
else {
if (ftp_mkdir($conn_id, $ftppath)) {
 echo "OK. Created the directory $ftppath \n";
}
else {
 echo "Fail. Error creating the directory $ftppath \n";
}
}


//Check The Day Directory
$contentsday = ftp_nlist($conn_id, "./$ftppath");
if (in_array("./$ftppath/$fullday", $contentsday)) {
    echo "OK. Directory $fullday exists. \n";
}
else {
if (ftp_mkdir($conn_id, "$ftppath/$fullday")) {
 echo "OK. Created the directory $fullday \n";
}
else {
 echo "Fail. Error creating the directory $fullday \n";
}
}


//Start uploading the file
$upload = ftp_put($conn_id, $dailydstfile, $dailysrcfile, FTP_BINARY);

//Check if the file is uploaded
if (!$upload) {
        echo"FAIL. Error uploading file \n";
    }
else {
        echo"OK. File Uploaded \n";
}


if ($dayofmonth == "01") {

echo "OK. It's THAT time of the month. (Starting Monthly Backup) \n";
  
//Check The month Directory
$contentsmonth = ftp_nlist($conn_id, "./$ftppath");
if (in_array("./$ftppath/Monthly", $contentsmonth)) {
    echo "OK. Directory Monthly exists. \n";
}
else {
if (ftp_mkdir($conn_id, "$ftppath/Monthly")) {
 echo "OK. Created the directory Monthly \n";
}
else {
 echo "Fail. Error creating the directory Monthly \n";
}
}


//Start uploading the monthly backup
$monthlyupload = ftp_put($conn_id, $monthdstfile, $monthsrcfile, FTP_BINARY);

//Check if the file is uploaded
if (!$monthlyupload) {
        echo"FAIL. Error uploading the monthly backup \n";
    }
else {
        echo"OK. Monthly backup Uploaded \n";
}

}


//Close the ftp connection
ftp_close($conn_id);

//Remove Temp File
exec("rm $backuppath$fullday.tgz ");

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.