定制 itop/laravel-restic 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

itop/laravel-restic

Composer 安装命令:

composer require itop/laravel-restic

包简介

A Laravel package to backup your application

README 文档

README

This package provides a class to help scheduling your backup using restic

Requirements

Go installation

Before using this package you have to install go and restic

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

If you have a previous version of Go installed, be sure to remove it before installing another.

Download the archive and extract it into /usr/local, creating a Go tree in /usr/local/go. For example, run the following as root or through sudo:

tar -C /usr/local -xzf go1.15.5.linux-amd64.tar.gz

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

export PATH=$PATH:/usr/local/go/bin

Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.

Verify that you've installed Go by opening a command prompt and typing the following command:

go version

Confirm that the command prints the installed version of Go.

Restic installation

Restic is a backup program that is fast, efficient and secure. It supports the three major operating systems (Linux, macOS, Windows) and a few smaller ones (FreeBSD, OpenBSD).

Ubuntu

On Debian, there’s a package called restic which can be installed from the official repos, e.g. with apt-get:

apt-get install restic

From Source

In order to build restic from source, execute the following steps:

git clone https://github.com/restic/restic
cd restic
go run build.go

if you have problems reaching go modules and repositories try:

GOPROXY=direct
go run build.go

or

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

For other installation guides for Linux distributions or windows go Restic installation

Basic installation

You can install this package via composer using:

composer require itop/laravel-restic

The package will automatically register its service provider.

To publish the config file to config/restic.php run:

php artisan vendor:publish --provider="Itop\Restic\ResticServiceProvider"

This is the default contents of the configuration:

Configuring

This is the default contents of the configuration:

<?php
return [

    'restic_binary_path' => '/var/www/restic/restic', 

    'repositories' => [

        'local' => [
            'backup_paths' => [
                '/var/www/katip/server/storage/',
                '/var/www/katip/web/storage/'
            ],
            'exclude_files' => [
                'vendor'
            ],
            'env' => [
                'RESTIC_PASSWORD'   => 'password',
                'RESTIC_REPOSITORY' => '/var/www/backup',
            ]
        ],

        'remote'  => [
            'backup_paths' => [
                '/var/www/katip/server/storage/',
                '/var/www/katip/web/storage/'
            ],
            'exclude_files' => [
                'vendor'
            ],
            'env' => [
                'RESTIC_PASSWORD'   => 'password',
                'RESTIC_REPOSITORY' => 'rest:https://user:password@host:port/user/',
            ]
        ],
    ],
];

For pathing options to restic use env section in config file. Full environment variables that using restic listed here

Commands

Init

Before you start to backup your files you have to init your repositories specified in config/restic.php. The place where your backups will be saved is called a “repository”. All repositories specified in config/resic.php that you want to backup should be initiated separately

php artisan restic:init local # or remote

Backup

Now we’re ready to backup some data. The contents of a directory at a specific point in time is called a “snapshot” in restic. Run the following command for creating first snapshot.

php artisan restic:backup local

If you run the backup command again, restic will create another snapshot of your data, but this time it’s even faster and no new data was added to the repository (since all data is already there). This is de-duplication at work!

for exclude files from backup you can path other options like:

php artisan restic:backup local --exclude="*.c" --exclude-file=excludes.txt

if --exclude option is not passed will be used specified in config/restic.php or in env section

Snapshots

Now, you can list all the snapshots stored in the repository:

php artisan restic:snapshots local

Forget

In order to remove the snapshots of local repository use the forget command and specify the snapshot ID on the command line:

php artisan restic:forget local forget bdbd3439

Removing snapshots manually is tedious and error-prone, therefore restic allows specifying which snapshots should be removed automatically according to a policy. You can specify how many hourly, daily, weekly, monthly and yearly snapshots to keep, any other snapshots are removed.

php artisan restic:forget local --keep-last 4 --tag foo --tag bar 

Prune

After removing a snapshot the data that was referenced by files in that snapshot is still stored in the repository. To cleanup unreferenced data, the prune command must be run:

php artisan restic:prune local

Every command also includes a "help" screen which displays and describes the command's available arguments and options. To view a help screen, precede the name of the command with help

php artisan restic:forget --help

Scheduling

See example of scheduling in App/Console/Kernel.php

$logPath = storage_path('logs/restic.log');

// Local repository
$schedule->command('restic:backup local')
->hourly()
->appendOutputTo($logPath);

$schedule->command('restic:forget local --keep-last=4')
->dailyAt('12:00')
->appendOutputTo($logPath);

// Remote repository
$schedule->command('restic:backup remote')
->hourly()
->appendOutputTo($logPath);

$schedule->command('restic:forget remote --keep-last=4')
->dailyAt('12:00')
->appendOutputTo($logPath);

itop/laravel-restic 适用场景与选型建议

itop/laravel-restic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「backup」 「itop」 「restic」 「laravel-restic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 itop/laravel-restic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 itop/laravel-restic 我们能提供哪些服务?
定制开发 / 二次开发

基于 itop/laravel-restic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-10