Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Backup.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/*
$backupDir = "/var/www/html/backup/";
$backupPath = "/var/www/html/backup/";

$backup = new Backup($backupDir);
$backup = new Backup($backupPath);
$backup->setMail("[YOUR EMAIL]");
$backup->setDeleteBackupsAfter(20);

Expand Down Expand Up @@ -38,7 +38,7 @@ class Backup
*/
public function __construct(string $backupPath)
{
$this->_backupDir = $backupPath;
$this->_backupDir = $this->validateUserInputFilePath($backupPath);
}

/**
Expand All @@ -47,6 +47,8 @@ public function __construct(string $backupPath)
*/
public function backupDirectory(string $directoryPath) : void
{
$directoryPath = $this->validateUserInputFilePath($directoryPath);

//avoid php timeouts
ini_set("max_execution_time", $this->_phpTimeoutTime);

Expand Down Expand Up @@ -274,6 +276,20 @@ private function deleteOldBackup() : array
return $deletedFiles;
}

/**
* Validates the given filePath
* @param string $filePath
* @return string
*/
private function validateUserInputFilePath(string $filePath) : string
{
$result = $filePath;
if(substr($result, -1) !== DIRECTORY_SEPARATOR){
$result .= DIRECTORY_SEPARATOR;
}
return $result;
}

//getter and setter

/**
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ git clone https://github.com/StefanSchomacker/PHPBackupScript
**Sample Setup**

Create a string with the path of your backup directory.
The last `/` is important!

Example:
```
$backupDir = "/var/www/html/backup/";
$backupPath = "/var/www/html/backup/";
```

Create an object of Backup::class

```
$backup = new Backup($backupDir);
$backup = new Backup($backupPath);
```

Set E-Mail for zip Archive
Expand Down Expand Up @@ -147,7 +146,7 @@ Feel free to create a new
- [x] MySQL database backup
- [x] user decide between backup files and db
- [x] separate mail of different backups
- [ ] validate user input
- [x] validate user input
- [x] set max_execution_time by function
- [ ] backup with runwhen

Expand Down