有没有一款软件可以有条件的备份和上传同步,并在达到多少个备份版本后删除旧文件

RT
机子跑了个小型ERP,能自动生成备份文件,考虑安全想上网盘同步备份。
但是文件太多了,一小时备份3次,一个差不多200M。占用带宽和网盘空间受不了。
有哪个可以条件备份并删除旧文件?
比如,常规同步了10个版本后,自动删除旧版本。每天夜晚再做一次备份上传,这次传到另一个文件夹。

写个脚本自动删?

#!/bin/bash
find ./ -mtime +10 -name "*.gz" -exec rm -rf {} \;
## -mtime +n : 列出在n天之前(不含n天本身)被更改过内容的文件名

我是程序自动备份完全不管,脚本删除 10 天之前的数据。

1 个赞

我正好也需要冗余备份,今天顺便解决了

#!/bin/bash

# source -> remote
source_path="source_path"
remote_path="remote_path"

# 备份文件夹名称
backup_folder="backup_$(date +%Y-%m-%d_%H:%M:%S)"

# 备份
cp -r "$source_path" "$remote_path/$backup_folder"

# 计数
backup_count=$(ls "$remote_path" | grep "backup_" | wc -l)

# 超过 10 个删除最旧版本
if [ $backup_count -gt 10 ]; then
    oldest_backup=$(find "$remote_path"/backup_* | sort | head -n 1)
    rm -rf "$oldest_backup"
fi

restic 和 kopia 都可以

Duplicati 应该是可以的,这个还支持增量备份,空间占用更小
开源,支持加密,支持上传至网盘,使用web ui管理
并且是多平台支持

文档:
The retention can be set in 5 ways:

  • Keep all backups:
    Backups will never be deleted. This is the most safe option, but remote storage capacity will keep increasing.
  • Delete backups that are older than:
    Backups older than a specified number of days, weeks, months or years will be deleted.
  • Keep a specific number of backups:
    The specified number of backup versions will be kept, all older backups will be deleted.
  • Custom backup retention: Enter your own settings in the text box that appears.
  • Smart backup retention: retains one backup for each of the last 7 days, each of the last 4 weeks, and each of the last 12 months.