承接 elektro-potkan/backups 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

elektro-potkan/backups

Composer 安装命令:

composer require elektro-potkan/backups

包简介

Backups

关键字:

README 文档

README

Manages backups for PHP projects. This repo holds main interfaces, basic Managers, Jobs and PurgeRules.

Usage

The package is built around the idea of backup manager, to which all backup jobs are registered. The manager also purges older backups using the purge rules, keeping the storage used for backups under control.

Example

// init
$purgeRule = new ElektroPotkan\Backups\PurgeRules\Rolling;

$manager = new ElektroPotkan\Backups\Managers\Locking('path-to-backups-directory', 'MyApp-v1.47.2', $purgeRule);

$manager->addJob('config', new ElektroPotkan\Backups\Jobs\FileCopy('config/main.cfg'));
$manager->addJob('readme', new ElektroPotkan\Backups\Jobs\File('txt', 'Some README notes to keep in the backup for future restore'));
$manager->addJob('data', new ElektroPotkan\Backups\Jobs\Callback('json',
	function(string $path) use($jsonSource): void {
		if($jsonSource->hasData()){
			file_put_contents($path, $jsonSource->getData());
		}
	}
));

// run periodically
$manager->create();
$manager->purge();

// backend management
$manager->list();
$manager->get($id);
$manager->delete($id);

// backup details
$backup = $manager->list()[0];
$backup->id;
$backup->time;
$backup->size;

$file = $backup->files[0];
$file->name;
$file->path;
$file->size;

Custom backup job

class MyJob implements ElektroPotkan\Backups\IJob {
	private $api;
	
	
	public function __construct($api){
		$this->api = $api;
	}
	
	public function create(string $path): void {
		if($this->api->hasData()){
			$this->api->saveData($path);
		}
	}
	
	public function getExtension(): string {
		return 'data';
	}
}


// register the new job
$myJob = new MyJob($myApi);

$manager->addJob('api', $myJob);

Custom purge rule

class MyRule implements ElektroPotkan\Backups\IPurgeRule {
	public function keepOrPurge(DateTimeInterface $dt, DateTimeInterface $now): bool {
		// keep backups from last 12 days and from January 1 of each year
		return $dt >= Nette\Utils\DateTime::from($now)->modify('- 12 days')->setTime(0, 0, 0, 0) || $dt->format('z') === '0';
	}
}

$purgeRule = new MyRule;

Job file-name

The jobs files are named using the schema:

timestamp_date_name_job-name.ext

E.g. for manager configured with MyApp-v1.47.2 as $name parameter, backup created at 2021-08-30 20:07:24 UTC, job added with the name test and returning extension txt, the resulting file-name would be:

1630354044_2021-08-30_MyApp-v1.47.2_test.txt

Logging

To log info and errors from built-in managers, You need to provide an implementation of ElektroPotkan\Backups\ILogger interface via setLogger call:

// $logger implements ElektroPotkan\Backups\ILogger
$manager->setLogger($logger);

If You are using Tracy, You can use the provided TracyLogger:

// $logger implements Tracy\ILogger
$manager->setLogger(new ElektroPotkan\Backups\TracyLogger($logger));

Author

Elektro-potkan git@elektro-potkan.cz

Info

Versioning

This project uses Semantic Versioning 2.0.0 (semver.org).

Branching

This project uses slightly modified Git-Flow Workflow and Branching Model:

License

You may use this program under the terms of either the BSD Zero Clause License or the GNU General Public License (GPL) version 3 or later.

See file LICENSE.

统计信息

  • 总下载量: 46
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: 0BSD
  • 更新时间: 2021-08-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固