SimpleBackup

PHP class


SimpleBackup is a simple class to backup or download files/database from your server

SimpleBackup PHP script

This script can be used to easily backup or download all data from your server. It consists of 2 parts - one to backup the files and one to dump th database from your server. In the basic setup you have to setup almost nohting to get started. For more advanced users the script allows to customize what to backup - which files to exclude, which tables to include, where to save the backup file etc. Every option is configurable also via URL parameters, so you can set up everything on the fly.

Features:

Example 1: One-step file backup

This example shows, how to make a backup of all files on the server. Just place the script in the folder which you want to backup.

<?php
   //  Example 1 - OneStep file backup
       require_once("BackupFiles.php");
       BackupFiles::backup();
?> 

Example 2: Minimal configuration database dump

In this example we make a database dump with the minimal setup needed

<?php  
  // Example 2 -  Minimal config DB dump
     require_once("BackupMySQL.php");
     BackupMySQL::simpleBackup('database','username','passwort','server');
?>

Example 3: Advanced example

Here and advanced example of how the script can be configured easily

<?php
  // Example 3
    $backup = new BackupFiles();
    $backup->setOutputBaseName("files")
           ->setSourceDirs(array("./"))
           ->setDestinationDir("backup")
           ->setExcludeDirs("backup")
           ->setOutput(Backup::LINK)
           ->setLoadFromRequest(true)
           ->backupFiles();
?>

Quick Start - instant use

To start using this script without any configuration - only 1 step is needed. This will download all the files in the directory where the script is placed. The default token is needed as a security measure (it can be changed later in th code)

1. Copy the 'backup.php' file in the root folder of your server and call the URL .

http://your.server.com/backup.php?token=backup*Files$2015

Any additional settings can be done adding URL params

http://your.server.com/backup.php?token=backup*Files$2015&exclude=someDirectory&output=link

 

Quick Start - customized use

If you need to customize anything or set some parameters (e.g. connection to the database), then the fastest way, without any programming is to add parameters to the URL. Here an example of how to quickly set up the script for an SQL dump.

1. Copy the 'backup.php' file in the root folder of your server

If you now call (like mentioned above) the script with this URL

http://your.server.com/backup.php?token=backup*Files$2015

=> the backup of the Files automatically starts - so the script works.

2. Set up the backup type (files or database)

But we now want to set up the database backup, so we add the parameter backup=db to the URL:

http://your.server.com/backup.php?token=backup*Files$2015&backup=db

3. Add the needed database configuration

Depending on your database server a few settings may be needed - servername, username, password and database name. Add all of the needed ones into the URL:

http://your.server.com/backup.php?token=backup*Files$2015&backup=db&server=localhost&username=john&password=123456&database=testdb

 

If you need more of the script, you can setup the script rather in the code as through the URL params, follow the setup below.

1. Include the class file you want to use in your code - either BackupFiles or BackupMySQL class

<?php
       require_once("BackupFiles.php");
 

2. Make a new instance


       $backup = new BackupFiles();

3. Set up the needed parameters

You can set any number of parameters with chaining methods. All properties can be set with a function setPropertyName(). A list of properties can be found in the class reference.


       $backup->setOutputBaseName("files")
              ->setOutput(Backup::LINK)
              ->setDestinationDir("backup");

4. Do the magic!


       $backup->backupFiles();

For the complete reference of functions and options, look into the class reference at this link:

http://praca.webax.sk/simple-backup/docu/classes/Backup.html
http://praca.webax.sk/simple-backup/docu/classes/BackupFiles.html

http://praca.webax.sk/simple-backup/docu/classes/BackupMySQL.html

 

 

 

If you want to see the backup script in action, check out the live demo:

http://praca.webax.sk/simple-backup/example1.php

http://praca.webax.sk/simple-backup/example2.php