mirror of
https://github.com/laurent22/rsync-time-backup
synced 2024-11-10 06:04:18 +00:00
Allow specifying the expiration strategy tokens in any order (less error prone)
This commit is contained in:
parent
c608793b60
commit
2d0cb29bcb
6 changed files with 73283 additions and 11 deletions
|
@ -75,6 +75,15 @@ fn_parse_date() {
|
|||
fi
|
||||
}
|
||||
|
||||
fn_run_cmd() {
|
||||
if [ -n "$SSH_DEST_FOLDER_PREFIX" ]
|
||||
then
|
||||
eval "$SSH_CMD '$1'"
|
||||
else
|
||||
eval $1
|
||||
fi
|
||||
}
|
||||
|
||||
fn_find_backups() {
|
||||
fn_run_cmd "find "$DEST_FOLDER" -maxdepth 1 -type d -name \"????-??-??-??????\" -prune | sort -r"
|
||||
}
|
||||
|
@ -108,8 +117,7 @@ fn_expire_backups() {
|
|||
fi
|
||||
|
||||
# Find which strategy token applies to this particular backup
|
||||
IFS=' '
|
||||
for strategy_token in $EXPIRATION_STRATEGY; do
|
||||
for strategy_token in $(echo $EXPIRATION_STRATEGY | tr " " "\n" | sort -r -n); do
|
||||
IFS=':' read -r -a t <<< "$strategy_token"
|
||||
|
||||
# After which date (relative to today) this token applies (X)
|
||||
|
@ -161,15 +169,6 @@ fn_parse_ssh() {
|
|||
fi
|
||||
}
|
||||
|
||||
fn_run_cmd() {
|
||||
if [ -n "$SSH_DEST_FOLDER_PREFIX" ]
|
||||
then
|
||||
eval "$SSH_CMD '$1'"
|
||||
else
|
||||
eval $1
|
||||
fi
|
||||
}
|
||||
|
||||
fn_find() {
|
||||
fn_run_cmd "find '$1'" 2>/dev/null
|
||||
}
|
||||
|
|
6
test.txt
Normal file
6
test.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
1:123
|
||||
2:123
|
||||
3:123
|
||||
10:123
|
||||
4:123
|
||||
20:123
|
5
tests/BaseTestCase.php
Normal file
5
tests/BaseTestCase.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BaseTestCase extends TestCase {}
|
40
tests/BasicTest.php
Normal file
40
tests/BasicTest.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
require_once dirname(__FILE__) . '/BaseTestCase.php';
|
||||
|
||||
class BasicTest extends BaseTestCase {
|
||||
|
||||
private function makeDir($dir) {
|
||||
if (!file_exists($dir)) {
|
||||
$ok = @mkdir($dir, 0777, true);
|
||||
if (!$ok) throw new Exception('Could not create source directory: ' . $dir);
|
||||
}
|
||||
return $dir;
|
||||
}
|
||||
|
||||
private function sourceDir() {
|
||||
return $this->makeDir(dirname(__FILE__) . '/data/source');
|
||||
}
|
||||
|
||||
private function destDir() {
|
||||
return $this->makeDir(dirname(__FILE__) . '/data/dest');
|
||||
}
|
||||
|
||||
private function scriptPath() {
|
||||
return dirname(dirname(__FILE__)) . '/rsync_tmbackup.sh';
|
||||
}
|
||||
|
||||
private function execScript($args) {
|
||||
$cmd = $this->scriptPath() . ' ' . implode(' ', $args);
|
||||
exec($cmd, $output, $errorCode);
|
||||
return array(
|
||||
'output' => $output,
|
||||
'errorCode' => $errorCode,
|
||||
);
|
||||
}
|
||||
|
||||
public function testFilesAreCopied() {
|
||||
//$this->execScript(
|
||||
}
|
||||
|
||||
}
|
3
tests/package-lock.json
generated
Normal file
3
tests/package-lock.json
generated
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"lockfileVersion": 1
|
||||
}
|
73219
tests/phpunit-5.7.20.phar
Normal file
73219
tests/phpunit-5.7.20.phar
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue