linux 备份信息查看器,linux 全新的备份神器 Duplicity

linux 全新的备份神器  Duplicity

Duplicity 使用 librsync 生产一个非常小的额外备份。它能够生成递增备份,然后使用 GPG 进行加密,能够适用常用的方法发送至另一个服务器上,比如:scp、ftp、sftp、rsync等等。可以从任何目录开始备份,不限于加载点(mountpoint),并且可以指定你想要排除的文件。

安装也很简单,使用yum安装和下载duplicity的源码包,编译安装也可以。

1.安装所需要依赖(安装epel源)

yum install -y gcc-c++ librsync python-lockfile python-urllib3 python-setuptools python-devel librsync-devel

2.下载duplicity源码包

3.解压,并安装

tar xvf duplicity-0.7.07.tar.gz

cd duplicity-0.7.07

python setup.py install

4.验证是否安装成功,并查看版本

echo $?

duplicity -V

如果使用yum无法安装,请安装epel的扩展源,再yum安装

www.lishiming.net/data/p_w_upload/forum/epel-release-6-8_64.noarch.rpm

http://duplicity.nongnu.org/duplicity.1.html

注意:在设置备份时,请同时备份好设置的密钥,如果密钥丢失,你备份的数据也无法解密,所以把密钥刻录多张cd作为多个备份。

语法:

duplicity [actions] [options] source_directory target_url

action:

full           会强制的完整备份,即使可以使用增量备份

incr           使用增量备份,但是第一次备份时会忽略,而使用完整备份

verify          比较备份和当前文件的修改时间

list-current-files    列出当前最新备份的文件

collection-status    列出备份的状态,有多少个完整备份及增量备份,备份的时间等等.

例如:

1.列出备份文件的状态

duplicity collection-status --ssh-options="-oPort=8888 -oIdentityFile=/home/abc/sK/id_rsa" sftp://mysftp@backup/  /upload/

#--ssh-options 指定链接所使用的端口号

#-oIdentityFile 指定ssh密钥的位置

2.删除存在的时间超过1年的文件

#--force 如果不加上这个这个参数,则是列出要删除的文件,而不会删除他们。

#remove-older-than 删除比指定时间要旧的文件

#--no-encryption   不加密,

案例:

1.本机备份

duplicity full --include /data/test/iptables  --exclude '**' /data file:///aaa

2.查看备份的文档

duplicity list-current-files file:///aaa ##/aaa为备份的路径

3.恢复备份

duplicity restore file:///aaa /data/restore  ##file:///aaa是备份的路径 ##/data/restore是还原到的路径

4.如果只想恢复完全备份中的某个文件是可以使用--file-to-restore选项

duplicity restore --file-to-restore=passwd file:///aaa /abc/passwd  ##--file-to-restore使用的是相对路径,file:///aaa是备份文件的路径,/abc/passwd是文件恢复的路径,passwd是指定的文件名

--restore-time "2002-01-25"  恢复某个特定时间的备份数据

--log-file /backup/test/$dir.log 指定日志文件

--tempdir /backup/tmp       指定临时文件路径

--encrypt-key=102CB07A      指定密钥加密

5.恢复指定时间备份的数据

duplicity restore --restore-time "2017-01-01T19:53:52" file:///aaa /bbb/passwd4

6.使用密钥尽享加密

duplicity full --encrypt-key=2A7669AD --include /etc/passwd --exclude '**' /etc file:///backup

如果想使用duplicity的更多应用,请使用man duplicity的详细。

更方便的是写成脚本,放在计划任务里面,自动备份

#!/bin/bash

export PASSPHRASE="xxxxxx"

#mkdir /mnt/df

#mount.cifs //192.168.0.100/E$ /mnt/df -o username='SHUOBAOTANG/administrator',password='xxxxx'

DIRS='aaa

bbb

ccc

internal_ldap

mail_backup

'

for dir in $DIRS; do

echo "start backup $dir"

#    mkdir /mnt/100/$dir

#    duplicity full --encrypt-key=102CB07A /mnt/21/e/$dir file:///mnt/69/$dir --log-file /bak/test/$dir.log --tempdir /bak/tmp --archive-dir /bak/tmp

duplicity full --encrypt-key=102CB07A /backup/$dir file:///mnt/50/e/$dir --log-file /home/log2/$dir.log --tempdir /home/tmp --archive-dir /home/tmp

duplicity verify --encrypt-key=102CB07A file:///mnt/50/e/$dir /backup/$dir --log-file /home/log2/$dir.log --tempdir /home/tmp --archive-dir /home/tmp

#    duplicity full --encrypt-key=102CB07A  scp://root@192.168.0.46//backup/chenmi/$dir /backup2/$dir --log-file /backup1/test/$dir.log --tempdir /backup1/tmp --archive-dir /backup1/tmp

#    duplicity verify --encrypt-key=102CB07A /backup2/$dir scp://root@192.168.0.46//backup/chenmi/$dir   --log-file /backup1/test/$dir.log --tempdir /backup1/tmp --archive-dir /backup1/tmp

done

You have mail in /var/spool/mail/root

格式如下:

duplicity [full|incremental] [options] source_directory target_url

duplicity verify [options] [--compare-data] [--file-to-restore ] [--time time] source_url

target_directory

duplicity collection-status [options] [--file-changed ]

target_url

duplicity list-current-files [options] [--time time] target_url

duplicity [restore] [options] [--file-to-restore ] [--time time] source_url

target_directory

duplicity remove-older-than  [options] [--force] target_url

duplicity remove-all-but-n-full  [options] [--force] target_url

duplicity remove-all-inc-of-but-n-full  [options] [--force] target_url

duplicity cleanup [options] [--force] [--extra-clean] target_url

编辑脚本,执行命令备份

vim duplicity.sh#!/bin/bash

# set up the GPG private key password

#这里设置的PASSPHRASE就是你的GPG密钥的密码

#PASSPHRASE=xxxxxx

#export PASSPHRASE

#set the ssh key password

#FTP_PASSWORD是你的ssh密钥的密码,导入到环境中就不用手动输入了

FTP_PASSWORD=mypassword

export FTP_PASSWORD

#upload server root ,exclude /proc /sys /tmp to sftp server,and no encryption

#下面是备份根目录,--exclude表示将 /proc /sys /tmp 除外 ,这里需要注意的是,duplicity文档中特别注明了如果你要备份根,那么必须要把 /proc除外

#下面的 --dry-run表示并没有实际运行,只是测试,而 --ssh-options后面的是ssh的一些设置,端口号为8888,ssh密钥的位置.

duplicity -v5 --dry-run --progress   --no-encryption --ssh-options="-oPort=8888 -oIdentityFile=/home/xx/private/id_rsa" --exclude /proc --exclude /sys --exclude /tmp / sftp://mysftp@youserver.locastion/upload/#unset varunset FTP_PASSWORD

备份虽然重要,单恢复更为重要。

在备份前,先列出所有备份的文件,确定好备份的文件在做相应的回复,如果命令不是很熟练的话,请先自己在别的机器上演戏几遍,以免发生不必要的错误。

1.列出备份的文件

duplicity list-current-files scp://mybackup/directoryname/home/

恢复某个特定日期的文件   添加:--restore-time "2016-09-22"

结论:Duplicity 非常棒,而且速度也很快。这是因为善用 libsync 让备份变得很小,同时也因为他们保持了备份文件的索引,这样为了获得文件列表无需对整个备份进行读取。备份文件很小,划分为多个小文件,这样源机器就不需太多的临时空间。用起来也非常简单:他们能够完成所有递增和完整备份的工作,从而让你能够把关注焦点放在对什么进行备份和恢复上。、

本文章是自己测试或参考网络文档。如果有错误请指出,或者与我交流。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值