1 安装
binary
cd ~
curl -LO https://github.com/restic/restic/releases/download/v*.*.*/restic_*.*.*_linux_amd64.bz
bunzip2 restic*
sudo mv restic* /usr/local/bin/restic
sudo chmod a+x /usr/local/bin/restic
ubuntu
apt install restic
centos
yum-config-manager --add-repo https://copr.fedorainfracloud.org/coprs/copart/restic/repo/epel-7/copart-restic-epel-7.repo
yum install restic -y
2 配置文件
vim ~/restic-env
export AWS_ACCESS_KEY_ID=***
export AWS_SECRET_ACCESS_KEY=***
export RESTIC_REPOSITORY="s3:http://s3.com/bucket"
export RESTIC_PASSWORD="***"
chmod 600 restic-env
3 初始化
source ~/restic-env
restic init
4 一般操作
source ~/restic-env
### 备份
restic backup /dir
### 查看
restic snapshots
### 恢复
restic restore 3726gdsc(snapshots ID) --target /dir
forget
参数选项:--keep-last n
keep the n last (most recent) snapshots.--keep-hourly n
for the last n hours which have one or more snapshots, keep only the most recent one for each hour.--keep-daily n
for the last n days which have one or more snapshots, keep only the most recent one for each day.--keep-weekly n
for the last n weeks which have one or more snapshots, keep only the most recent one for each week.--keep-monthly n
for the last n months which have one or more snapshots, keep only the most recent one for each month.--keep-yearly n
for the last n years which have one or more snapshots, keep only the most recent one for each year.--keep-tag keep
all snapshots which have all tags specified by this option (can be specified multiple times).--keep-within
duration keep all snapshots having a timestamp within the specified duration of the latest snapshot, where duration is a number of years, months, days, and hours. E.g. 2y5m7d3h will keep all snapshots made in the two years, five months, seven days and three hours before the latest (most recent) snapshot.--keep-within-hourly
duration keep all hourly snapshots made within the specified duration of the latest snapshot. The duration is specified in the same way as for --keep-within and the method for determining hourly snapshots is the same as for --keep-hourly.--keep-within-daily
duration keep all daily snapshots made within the specified duration of the latest snapshot.--keep-within-weekly
duration keep all weekly snapshots made within the specified duration of the latest snapshot.--keep-within-monthly
duration keep all monthly snapshots made within the specified duration of the latest snapshot.--keep-within-yearly
duration keep all yearly snapshots made within the specified duration of the latest snapshot.
5 定时任务
crontab -e
### 每周二晚上四点备份, 并清除三周前的备份, 保留三周内的备份
0 4 * * 2 . ~/restic-env; /usr/bin/restic(or /usr/local/bin/restic) backup -q /dir; /usr/bin/restic forget -q --prune --keep-weekly 3
Lasted update: Apr 12, 2022 at 03:57 pm