backupper用于上传和管理owncloud中的文件。
owncloud_backup的Python项目详细描述
拥有云备份
此项目用于将备份上载到owncloud并管理旧备份。
工作原理
默认情况下,脚本需要一个file参数,该参数将以%Y.%m.%d_time前缀上载到远程路径目录中。
上载文件时,脚本请求列出选定的远程路径中的所有其他文件,然后从名称中读取时间信息,然后删除旧文件。
删除旧文件的过程定义为保留以下文件:
- 上个月的所有文件
- 两个月前每周一份文件
- 三个月前,每两周提交一份文件
删除所有旧文件。
配置
有可能使用conf文件owncloud_backup.cfg或~/.owncloud_backup.cfg配置以下变量:
[Login] user=login@owncloud.tld pass=password url=https://owncloud.cesnet.cz [Config] remote_path=/backups no_timestamp=false
config节和url节中的变量的所有值都是可选的(本例中显示了默认值)。
没有时间戳将指示脚本停止将时间戳前缀放入上载的文件。在这种情况下,预计这些文件将包含手动添加的时间戳,否则在删除旧文件的过程中将忽略它们。
命令行参数
也可以使用命令行参数添加配置文件中定义的所有变量:
usage: owncloud_backup.py [-h] [-u USERNAME] [-p PASSWORD] [--url URL] [-r REMOTE_PATH] [-n] FILENAME This program may be used to perform database backups into ownCloud. Configuration file in ini format is expected in `owncloud_backup.cfg` or `~/.owncloud_backup.cfg` paths. positional arguments: FILENAME Upload FILENAME into the ownCloud. optional arguments: -h, --help show this help message and exit -u USERNAME, --username USERNAME Username of the ownCloud user. -p PASSWORD, --password PASSWORD Password of the ownCloud user. --url URL URL of the ownCloud service. Default `https://owncloud.cesnet.cz`. -r REMOTE_PATH, --remote-path REMOTE_PATH Path on the server. Default `/backups`. -n, --no-timestamp By default, the script adds `%Y.%m.%d_` prefix to each uploaded file.
在SUSE上安装
如果您使用的是带有旧python版本且没有pip的古代suse安装,则可以使用以下命令安装它:
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-20.0.zip unzip setuptools-20.0.zip cd setuptools-20.0/ python setup.py install easy_install pip==1.2 pip install -U owncloud_backup
单元测试
几乎项目的每个特性都是由unittests测试的。你可以运行那些 使用提供的run_tests.sh脚本进行测试,该脚本可以在根目录中找到 项目的一部分。
如果有任何问题,只需在run_tests.sh命令的末尾添加--pdb开关,如下所示:./run_tests.sh --pdb。这将把您放到PDBshell。
示例
./run_tests.sh ============================= test session starts ============================== platform linux2 -- Python 2.7.6, pytest-2.8.2, py-1.4.30, pluggy-0.3.1 rootdir: /home/bystrousak/Plocha/Dropbox/c0d3z/prace/owncloud_backup, inifile: plugins: cov-1.8.1 collected 3 items tests/test_backup.py ... =========================== 3 passed in 0.47 seconds ===========================
更改日志
0.1.6
- Fixed bug in removing old files on remote server.
0.1.5
- Added mute of the InsecurePlatformWarning.
0.1.4
- Fixed bugs in argument parsing priority.
0.1.3
- Added few other python2.6 updates.
0.1.2
- Removed set comprehension to support python2.6.
0.1.1
- Added scripts declaration into setup.py.
0.1.0
- Project created.