使用 python 的修订控制脚本

发布于 2024-11-04 11:27:26 字数 631 浏览 0 评论 0原文

我正在读这个问题 https://stackoverflow.com/questions/38388/organization-wide-backup -strategy

我对实施这个系统很感兴趣

修订控制由一个 扫描文件系统的Python脚本 并将更改的文件上传到中央 服务器。该服务器上的文件系统 广泛使用 Unix 风格 符号链接 - 即只有一份副本 给定的文件曾经被存储过, 后续副本只是符号链接 到。这可以让你有一个完整的 为每天创建的文件系统 备份但只使用一小部分 它使用的实际磁盘空间(您 只需要有足够的空间来容纳任何文件 自上次备份以来已更改并更改为 存储所有这些符号链接)。这是 一般原则是这样的事情 Mac的Time Machine系统使用。用户 需要恢复旧文件可以 只需浏览该文件系统即可。

任何人都可以给我一些指南或教程,或者一些可以在 Python 中使用的脚本。我最想看到的是如何拥有每天的虚拟文件系统,而不使用太多空间

我是 python 新手

I am was reading this SO question https://stackoverflow.com/questions/38388/organization-wide-backup-strategy

And i was interested in implementing this system

Revision control is handled by a
Python script that scans a file system
and uploads changed files to a central
server. The file system on that server
makes extensive use of Unix-style
symbolic links - i.e. only one copy of
a given file is ever stored,
subsequent copies are simply symlinked
to. This allows you to have a full
file system created for each day's
backup but to only use a fraction of
the actual disk space it uses (you
just need enough space for any files
changed since the last backup and to
store all those symlinks). This is the
general principle that things like the
Mac's Time Machine system uses. Users
needing to restore an old file can
simply browse that file system.

Can anyone give me some guide lines or tutorials or some rready to use script like that in Python . the best thing i would like to see is how to have virtual file system of every day , without using too much space

I am newbie in python

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2024-11-11 11:27:26

rsync + 硬链接。

使用 rsync 维护主备份目录。
使用 cp -al 拍摄每日/每周/任何快照。

使用硬链接意味着重复的文件不会占用额外的空间,即每个快照只会占用已更改的文件中的空间。此外,每个快照都包含备份的完整副本,并且将保留备份的符号链接。

我有一个用于管理快照的 python 包装器 - 保留预定义数量的每日、每周、每月和每年快照,但您可以根据需要将其保持为复杂或简单。

这里是灵感的重要来源:http://www.mikerubel.org/computers/rsync_snapshots/

更新:

示例备份:

# generate some test data
mkdir /tmp/backup
mkdir documents
date > documents/file1
date > documents/file2

# do the backup
rsync -av --delete documents /tmp/backup/
cp -al /tmp/backup /tmp/backup.$(date +%Y%m%d-%H%M%S)

现在您应该有一个具有当前状态(/tmp/backup)的主备份和一个日期备份/tmp/backup..对于下一个备份,只需再次运行 rsync 和 cp:

# modify the test data
date >> documents/file1

# do the backup
rsync -av --delete documents /tmp/backup/
cp -al /tmp/backup /tmp/backup.$(date +%Y%m%d-%H%M%S)

请注意,rsync 只会更新已更改的文件,因此在备份时间方面这是优化的。由于您对未更改的文件使用硬链接,因此它的存储效率也非常高。

rsync + hard links.

use rsync to maintain a master backup directory.
use cp -al to take daily/weekly/whatever snapshots.

Using hard links means duplicated files will not take up additional space, i.e. each snapshot will only use up the space in the files that have changed. In addition each snapshot contains a complete copy of the backup and symlinks that get backed up will be preserved.

I have a python wrapper for this that manages the snapshots - keeping a predefined number of daily, weekly, monthly and yearly snapshots, but you can keep this as elaborate or simple as you want.

Great source of inspiration here: http://www.mikerubel.org/computers/rsync_snapshots/

Update:

sample backup:

# generate some test data
mkdir /tmp/backup
mkdir documents
date > documents/file1
date > documents/file2

# do the backup
rsync -av --delete documents /tmp/backup/
cp -al /tmp/backup /tmp/backup.$(date +%Y%m%d-%H%M%S)

Now you should have a master backup with the current state (/tmp/backup) and a dated backup /tmp/backup.. For the next backup, just run the rsync and cp again:

# modify the test data
date >> documents/file1

# do the backup
rsync -av --delete documents /tmp/backup/
cp -al /tmp/backup /tmp/backup.$(date +%Y%m%d-%H%M%S)

Note that rsync will only update files that have changed, so in terms of backup time this is optimised. As you're using hard links for files that are unchanged, it is also very efficient for storage too.

巴黎盛开的樱花 2024-11-11 11:27:26

只需使用 Mercurial - 一个用 Python 编写的优秀源代码控制系统。它也是当今最流行的 SCM 之一。

Just use Mercurial - a great source control system written in Python. It's also one of teh most popular SCMs these days.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文