Example #1
0
 /**
  * @test
  */
 public function adds_file_to_collection()
 {
     $backup = new Backup($this->dropboxInstance(), $this->working);
     $backup->addJob(new Job(new FileJob($this->css_file(), $this->assets), 'files'));
     $backup->addJob(new Job(new FileJob($this->terms_file(), $this->assets), 'files'));
     $backup->prepare();
     $backup->processFiles();
     $this->assertCount(1, $backup->getCollection(), 'Files are not in the collection');
     $this->assertCount(2, $backup->getCollection()['files'], 'There are more or less than 2 items in the "files" item of the collection');
 }
Example #2
0
 /**
  * @test
  */
 public function adds_directory_to_collection_with_exclusion()
 {
     $backup = new Backup($this->dropboxInstance(), $this->working);
     $backup->addJob(new Job(new DirectoryJob($this->css_directory(), $this->assets, [$this->css_components_directory()]), 'directories'));
     $backup->prepare();
     $backup->processDirectories();
     $this->assertCount(1, $backup->getCollection()['directories'], 'There is more then 1 item in the "directories" collection');
 }
Example #3
0
 /**
  * @test
  */
 public function adds_jobs()
 {
     $backup = new Backup($this->dropboxInstance(), $this->working);
     $backup->addJob(new Job(new MySQLDatabase(['host' => 'foo', 'name' => 'bar', 'user' => 'abc', 'password' => 'password']), 'database'));
     $backup->addJob(new Job(new PostgreSQLDatabase(['host' => 'foo', 'name' => 'bar', 'user' => 'abc', 'password' => 'password']), 'database'));
     $backup->addJob(new Job(new File($this->css_file(), $this->css_directory())));
     $backup->addJob(new Job(new Directory($this->css_components_directory(), $this->css_directory())));
     $jobs = $backup->getJobs();
     $this->assertEquals(4, count($jobs), 'Number of jobs does not equal 4');
     $this->assertEquals('database', $jobs[0]->namespace, 'MySQLDatabase job namespace is not set to "database"');
     $this->assertInstanceOf(MySQLDatabase::class, $jobs[0]->job, 'Job is not instance of MySQLDatabase');
     $this->assertInstanceOf(PostgreSQLDatabase::class, $jobs[1]->job, 'Job is not instance of PostgreSQLDatabase');
     $this->assertEmpty($jobs[2]->namespace, 'File job namespace is not empty');
     $this->assertInstanceOf(File::class, $jobs[2]->job, 'Job is not instance of File');
     $this->assertEmpty($jobs[3]->namespace, 'Directory job namespace is not empty');
     $this->assertInstanceOf(Directory::class, $jobs[3]->job, 'Job is not instance of Directory');
 }
Example #4
0
 /**
  * @test
  */
 public function creates_archive()
 {
     $backup = new Backup($this->dropboxInstance(), $this->working);
     $backup->addJob(new Job(new File($this->terms_file(), $this->assets)));
     $backup->prepare();
     $backup->processFiles();
     $archive = new Archive($backup, new ZipArchive());
     $archive->execute();
     $this->add_file_to_remove($backup->archivePath());
     $this->assertFileExists($backup->archivePath());
 }
Example #5
0
 /**
  * @test
  */
 public function cleans_collection()
 {
     $backup = new Backup($this->dropboxInstance(), $this->working);
     $backup->addJob(new Job(new File($this->terms_file(), $this->assets)));
     $backup->prepare();
     $backup->processFiles();
     $archive = new Archive($backup, new ZipArchive());
     $archive->execute();
     $this->assertCount(1, $backup->getCollection(), 'Collection does not contain 1 item');
     $this->assertFileExists($backup->archivePath());
     $cleanup = new Cleanup($backup);
     $cleanup->execute();
     $this->assertEmpty($backup->getCollection(), 'Collection is not empty');
     $this->assertFileNotExists($backup->archivePath());
 }
Example #6
0
$dotenv->load();
$dotenv->required(['DROPBOX_SECRET', 'DROPBOX_OAUTH', 'FTP_HOST', 'FTP_USER', 'FTP_PASS', 'DOMAIN_NAME', 'DB_HOST', 'DB_PORT', 'DB_NAME', 'DB_USER', 'DB_PASS']);
// working directory
$workingDirectory = __DIR__ . '/tmp';
try {
    $remote = new Dropbox(getenv('DROPBOX_OAUTH'), getenv('DROPBOX_SECRET'));
    //$remote = new Ftp(
    //    getenv('FTP_HOST'),
    //    getenv('FTP_USER'),
    //    getenv('FTP_PASS'),
    //    [
    //        'root' => 'public_html'
    //    ]
    //);
    $backup = new Backup($remote, $workingDirectory);
    // directory to which backup should be saved on the remote server
    $backup->setRemoteDirectory(getenv('DOMAIN_NAME'));
    // keep only 7 backups then overwrite the oldest one
    $backup->setNumberOfBackups(7);
    // add MySQL database to the backup
    $backup->addJob(new Job(new MySQLDatabase(['host' => getenv('DB_HOST'), 'name' => getenv('DB_NAME'), 'user' => getenv('DB_USER'), 'password' => getenv('DB_PASS')]), 'database'));
    // add single file ot the backup
    $backup->addJob(new Job(new File(__DIR__ . '/files/text.txt', __DIR__)));
    // add the entire directory to the backup
    $backup->addJob(new Job(new Directory(__DIR__ . '/files', __DIR__, ['files/css'])));
    // run backup
    $backup->run();
} catch (Exception $e) {
    $file = $workingDirectory . DIRECTORY_SEPARATOR . 'error_log';
    file_put_contents($file, $e->getMessage() . PHP_EOL, FILE_APPEND | LOCK_EX);
}