How often do you backup?

Version 3 Solutions you have discovered or come across should go here. Questions should go in the other three Version 3 forums, thank you.
Forum rules
Please do not ask questions here, this is for Version 3 Solutions you have discovered or come across.

How often do you backup?

Postby Dragonrider » 8:31pm, Sat 04 Jan, 2014

How often do you backup your phpList database? Once a blue moon or never? Just like I used to do I guess.

It's not the easiest thing to do if you are not 100% confident with your web space Admin Panel, be it cPanel or Plesk or whatever. It also takes time to get into the habit.

What happens though when your database is corrupted, or your phpList install suffers a hack or some sort of attack? Or what if you deleted a subscriber, or worse still, a list and you now realise you want it back!

Here's my solution for all the above.

First of all, copy and paste the code below into your text editor (NotePad, Editpad or whatever) and make the changes to the first section so that (a) the include points to your phplist/config/config.php file. This allows the file to collect most of the settings phpList uses to set up this file so that a CRON job will run without too much effort.

Then (b) change the CAPITALS in $filename to be the file name you wish to use, (c) $to to become the email address you wish to receive the backup file and (d) $from to which email is available on your server to send your file from.

Finally (e) change YOUR in the $subject to refer to your phpList install, important if you have more than one.

Code: Select all

/* configure the following variables  in CAPITALS to match your setup */

include('/home/YOUR_DETAILS/public_html/YOUR_PHPLIST_DIR/config/config.php');  // Path to your phplist config.php file
// If your server uses www rather than public_html (above) change it. Likewise if your server uses root instead of home (above).

$dbuser = $database_user;            // Database username
$dbhost = "";                 // Might need to be or localhost or something specific to your server
$dbpwd = $database_password;            // Database password
$dbname = $database_name;            // Database name.
$filename= "FILENAME.sql.gz";   // The name of the dump file
$to = "EMAIL ADDRESS TO RECEIVE AT";      // Email address to send dump file to
$from = "EMAIL ADDRESS TO SEND FROM";      // Email address message will show as coming from.
$subject = "MySQL Backup of YOUR phpList Database";      // Subject of email
// End of User Configuration!!

$datestamp = date("Y-m-d");      // Current date to append to filename of backup file in format of YYYY-MM-DD

$command = "mysqldump  -h $dbhost -u $dbuser -p$dbpwd $dbname | gzip > $filename";
$result = passthru($command);

$attachmentname = array_pop(explode("/", $filename));   // If a path was included, strip it out for the attachment name

$message = "Compressed database backup file $attachmentname attached.";
$mime_boundary = "<<<:" . md5(time());
$data = chunk_split(base64_encode(implode("", file($filename))));

$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"\r\n";

$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content.= $message."\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Disposition: attachment;\r\n";
$content.= "Content-Type: Application/Octet-Stream; name=\"$attachmentname\"\r\n";
$content.= "Content-Transfer-Encoding: base64\r\n\r\n";
$content.= $data."\r\n";
$content.= "--" . $mime_boundary . "\r\n";

mail($to, $subject, $content, $headers);
unlink($filename);   //delete the backup file from the server

Save the file as cron.php (important to select php in the file type drop down menu here).

Now save this file to your server, preferably above your root/home directory or at the very least, above your phpList installation directory. (I'll attach the file to this Topic but you'll still need to make the changes above).

To run it, you'll need a CRON job setting up, compared with setting a CRON job to precess a queue in phpList, this is fairly simple, providing you have access to your web server admin panel. Log on to the admin cPanel/Plesk and look for Cron Jobs.

If you don't have access to CRON on your web space package, then have a look at sites like for a free CRON setup job.

If you have CRON available on your server, set up a standard CRON job pointing to the file you uploaded, I've called mine cron.php

Cron job I use:-
Code: Select all
php -q /home/USERNAME/backups/cron.php

With the cron settings of 0 0 * * 0 which tells the server to run once a week on the hour of midnight server time on a Sunday.

Note that you will need to use your own Username here (the same as your web space username) and I store my cron/php files in the directory backups, above the public_html directory. Because we are using CRON jobs which are actioned on the server, this is ok.

I would just like to add that the code was found on my Host's help pages, though there were a few glitches that had crept in due to their copy & paste from somewhere else, and I've modified it for minimum set up changes and to automatically pick up what data it can from your phpList config file.
(1.14 KiB) Downloaded 298 times
My sites:-,,,
Latest phpList version is now 3.0.12 (3 February 2015) and requires a minimum of MySQL 5.0 and PHP 5.3.x
Posts: 3460
Joined: 6:58am, Sun 02 Jul, 2006
Location: Ilkley, West Yorkshire, United Kingdom

Re: How often do you backup?

Postby jimlongo » 4:21pm, Tue 07 Jan, 2014

Every night just in case.

Mine is just a little different (probably modified from the same original source as yours). Runs nightly and sends the sql.tar.gz to a free ftp server account at DriveHQ.

Code: Select all
$datestamp = date("Y-m-d");         // datestamp format
$dbuser = "USERNAME";               // Database username
$dbpwd = "USER_PASSWORD";           // Database password
$dbname = "DB_NAME";               // Database name.
$filename= "sqlBU_MyPhpList-$datestamp.sql.gz";   //name of dump file
$ftp_server = "";    // Name or IP.
$ftp_port = "21";               // FTP port
$ftp_username = "FTP_USERNAME";     // FTP account username
$ftp_password = "FTP_PASSWORD";     // FTP account password

$command = "mysqldump --add-drop-table -u $dbuser --password=$dbpwd $dbname | gzip  > $filename";
$result = passthru($command);

$ftp_conn = ftp_connect($ftp_server);
ftp_pasv($ftp_conn, true);
$login_result = ftp_login($ftp_conn, $ftp_username, $ftp_password);
if ((!$ftp_conn) || (!$login_result))
      echo "FTP connection has failed.";
      echo "Attempted to connect to $ftp_server for user $ftp_username";
      echo "Connected to $ftp_server, for user $ftp_username";

$upload = ftp_put($ftp_conn, $filepath, $filename, FTP_BINARY);
if (!$upload)
      echo " FTP upload has failed.";
      echo " Uploaded $filename to $ftp_server.";


PL Geek
Posts: 88
Joined: 10:10pm, Tue 15 May, 2007

Re: How often do you backup?

Postby Kingsajz » 1:55pm, Tue 18 Feb, 2014

For my commercial project, I backup every day however for not commercial a week or a month. Its really annoying but what we can do.
phpList newbie
Posts: 2
Joined: 1:51pm, Tue 18 Feb, 2014

Re: How often do you backup?

Postby adoni » 3:05pm, Tue 06 May, 2014

Our servers all use raid

And the raid is backed up via R1soft every so many hours throughout day to a remote location just in case a nuke goes off in that city.

So raid runs 20 or so bucks a month, a 2nd drive for the raid runs 20 or so a month, and R1soft is usually .30 cents a gig per month of high storage use.

So let's say you have 100gig of data on the server

raid card 20
2nd drive 20

r1 soft remote backup in case of castastrophy to the NOC

30 bucks per 100gig

so for 70 bucks a month you have a professional backup routine

the raid can fix any HD failures on the spot

if the NOC is taken out, your data is in a remote location

that's a backup routine

we don't backup anything really

raids and remote automatics are how you do it
PL Nut
Posts: 16
Joined: 7:47pm, Mon 05 May, 2014

Return to Answers, HowTos, Tips and Tricks

Who is online

Users browsing this forum: No registered users and 0 guests