20230424--简朴备份工具rdiff-backups使用

分享
计算机软件开发 2024-10-2 08:02:30 18 0 来自 中国
1.备份

1)当地备份
# rdiff-backup /source-dir /dest-dir# rdiff-backup [源目次] [目标目次]生存目标目次的内容与生存源目次雷同。唯一差异的是,添加了一个名为rdiff-backup-data/的管理目次。如果再实验一次雷同的下令,这次只复制有变更的文件(增量备份)。 文件增量被压缩并存储在rdiff-backup-data/increments中。eg:
# rdiff-backup /etc /backup/etc# ll /backup/etc/rdiff-backup-data/total 76-rw-------  1 root root     0 Apr 19 20:14 access_control_lists.2023-04-19T20:14:18+08:00.snapshot...drwx------ 80 root root  4096 Apr 19 20:14 increments...# ll /backup/etc/rdiff-backup-data/increments/total 0drwx------ 2 root root  6 Apr 19 20:14 alternativesdrwx------ 4 root root 38 Apr 19 20:14 audit...2)当地数据备份到长途服务器
# rdiff-backup /source-dir user@server::/dest-direg:
# rdiff-backup  /var/log/ root@172.26.37.161::/backup/201_var_log3)当地备份长途服务器数据
# rdiff-backup user@server::/dest-dir /source-direg:
# rdiff-backup root@172.26.37.201::/var/log/ /backup/201_var_log/4)将长途服务器A的数据备份到长途服务器B
# rdiff-backup -v5 --print-statistics userX@serverN::/source-dir userY@hostM::/dest-direg:
WARNING: this command line interface is deprecated and will disappear, start using the new one as described with '--new --help'.* Executing remote command ssh -C root@172.26.37.201 rdiff-backup --terminal-verbosity 5 --serverroot@172.26.37.201's password: NOTE: Remote version 2.0.5 doesn't know about API versions but should be compatible with 200* Executing remote command ssh -C root@172.26.37.161 rdiff-backup --terminal-verbosity 5 --serverroot@172.26.37.161's password: * API version agreed to be 200 with command b'ssh -C root@172.26.37.161 rdiff-backup --terminal-verbosity 5 --server'* Using repository '/backup/201_var_log'* Given repository doesn't need to be regressedNOTE: Starting increment operation from source path /var/log to destination path /backup/201_var_log--------------[ Session statistics ]--------------StartTime 1682039613.00 (Fri Apr 21 09:13:33 2023)EndTime 1682039614.24 (Fri Apr 21 09:13:34 2023)ElapsedTime 1.24 (1.24 seconds)SourceFiles 130SourceFileSize 27902453 (26.6 MB)MirrorFiles 130MirrorFileSize 27887407 (26.6 MB)NewFiles 0NewFileSize 0 (0 bytes)DeletedFiles 0DeletedFileSize 0 (0 bytes)ChangedFiles 7ChangedSourceSize 7100194 (6.77 MB)ChangedMirrorSize 7085148 (6.76 MB)IncrementFiles 7IncrementFileSize 1417 (1.38 KB)TotalDestinationSizeChange 16463 (16.1 KB)Errors 0--------------------------------------------------* Cleaning upUsing rdiff-backup version 2.0.5        with cpython /usr/bin/python3 version 3.6.8        on Linux-3.10.0-693.11.6.el7.x86_64-x86_64-with-centos-7.4.1708-Core, fs encoding utf-8Sending back exception 'api_version' of type <class 'KeyError'>:   File "/usr/lib64/python3.6/site-packages/rdiff_backup/connection.py", line 400, in answer_request    result = eval(request.function_string)(*argument_list)  File "/usr/lib64/python3.6/site-packages/rdiff_backup/Globals.py", line 276, in get    return globals()[name]Unable to import win32security module. Windows ACLsnot supported by filesystem at /var/logWARNING: this command line interface is deprecated and will disappear, start using the new one as described with '--new --help'.* Starting server* -----------------------------------------------------------------Detected abilities for source (read only) file system:  Access control lists                         On  Extended attributes                          On  Windows access control lists                 Off  Case sensitivity                             On  Escape DOS devices                           Off  Escape trailing spaces                       Off  Mac OS X style resource forks                Off  Mac OS X Finder information                  Off-----------------------------------------------------------------* Unable to import win32security module. Windows ACLs not supported by filesystem at path /backup/201_var_log/rdiff-backup-data/rdiff-backup.tmp.0* -----------------------------------------------------------------Detected abilities for destination (read/write) file system:  Ownership changing                           On  Hard linking                                 On  fsync() directories                          On  Directory inc permissions                    On  High-bit permissions                         On  Symlink permissions                          Off  Extended filenames                           On  Windows reserved filenames                   Off  Access control lists                         On  Extended attributes                          On  Windows access control lists                 Off  Case sensitivity                             On  Escape DOS devices                           Off  Escape trailing spaces                       Off  Mac OS X style resource forks                Off  Mac OS X Finder information                  Off-----------------------------------------------------------------* Backup: escape_dos_devices = False* Backup: escape_trailing_spaces = False* Processing changed file /backup/201_var_log* Incrementing mirror file /backup/201_var_log* Processing changed file /backup/201_var_log/audit* Incrementing mirror file /backup/201_var_log/audit* Processing changed file audit/audit.log* Incrementing mirror file /backup/201_var_log/audit/audit.log* Processing changed file cron* Incrementing mirror file /backup/201_var_log/cron* Processing changed file maillog* Incrementing mirror file /backup/201_var_log/maillog* Processing changed file messages* Incrementing mirror file /backup/201_var_log/messages* Processing changed file secure* Incrementing mirror file /backup/201_var_log/secure* Cleaning up重要参数
--print:在处置处罚竣事时输出效果的选项。
--print-statistics:运行后的效果统计信息
--exclude-filelist :使用扫除列表
--exclude-other-filesystems:如果子目次中装载了其他文件体系,则将其扫除
--exclude-fifos:扫除定名管道的文件
--exclude-sockets:扫除socket文件
--exclude-special-files:扫除全部device文件、fifo文件、socket文件和符号链接文件
--exclude-symbolic-links:扫除符号链接文件
--max-file-size size:扫除指定巨细以上的文件
--min-file-size size:扫除指定巨细以下的文件
2.规复

1)规复到最新状态,使用[-r now]参数
# rdiff-backup -r now user@server::/remote-dir/file /local-dir/fileeg:
# rm -rf  /var/log# ll /var/logls: cannot access /var/log: No such file or directory# rdiff-backup -r now root@172.26.37.161::/backup/201_var_log /var/log/# ll /var/logtotal 13396drwx--S---. 2 amandabackup disk         6 Aug  1  2017 amandadrwxr-xr-x. 2 root         root       204 Dec 11  2017 anacondadrwx------. 2 root         root        42 Apr 17 10:20 audit...2)规复到指定时间点,起首用[-l]参数确认
# rdiff-backup -l user@server::/remote-dir/fileeg:
# rdiff-backup -l root@172.26.37.161::/backup/201_var_logroot@172.26.37.161's password: Found 3 increments:    increments.2023-04-21T08:53:54+08:00.dir   Thu Apr 20 20:53:54 2023    increments.2023-04-21T09:11:07+08:00.dir   Thu Apr 20 21:11:07 2023    increments.2023-04-21T09:13:33+08:00.dir   Thu Apr 20 21:13:33 2023Current mirror: Thu Apr 20 21:56:26 20233)规复到指定时间点状态,使用[-r XXX]参数
# rdiff-backup -r 「YYYY-MM-DD」T「H:M:S」+「时区」 user@server::/remote-dir/file -r 「YYYY-MM-DD」T「hh:mm:ss」+「时区」:2017-12-12T12:27:16+08:00eg:
# rm -rf  /var/log# rdiff-backup -r 2023-04-21T08:53:54+08:00 root@172.26.37.161::/backup/201_var_log /var/log/方法2:
# rdiff-backup -r 「时间」 user@server::/remote-dir/file时间的格式s -->; secondsm -->; minutesh -->; hoursD -->; daysW -->; weeksM -->; monthsY -->; yearsB -->; newest incrementeg:
# rm -rf  /var/log# rdiff-backup -r 2m root@172.26.37.161::/backup/201_var_log /var/log/3.旧备份删除

1)删除旧备份
# rdiff-backup --remove-older-than 1M  user@server::/remote-dir单位可以指定s, m, h, D, W, M, Y --remove-older-than 2016-01-07T23:25:22+09:00也可以像如许直接指定时间eg:
# rdiff-backup -l root@172.26.37.161::/backup/201_var_log# rdiff-backup --remove-older-than 1D --force root@172.26.37.161::/backup/201_var_logroot@172.26.37.161's password: WARNING: this command line interface is deprecated and will disappear, start using the new one as described with '--new --help'.Warning: Local version 2.0.5 does not match remote version 2.2.4.Deleting increments at times:Thu Apr 20 20:53:54 2023Thu Apr 20 21:11:07 2023Thu Apr 20 21:13:33 20232)只生存已往N次的备份,删除N次之前的备份
(以下只生存已往20次的备份,20次前的备份删除)
# rdiff-backup --remove-older-than 20B user@server::/remote-direg:
# rdiff-backup -l root@172.26.37.161::/backup/201_var_logroot@172.26.37.161's password: Found 2 increments:    increments.2023-04-21T09:56:26+08:00.dir   Thu Apr 20 21:56:26 2023    increments.2023-04-24T16:38:50+08:00.dir   Mon Apr 24 04:38:50 2023Current mirror: Mon Apr 24 04:39:19 2023# rdiff-backup --remove-older-than 1B --force root@172.26.37.161::/backup/201_var_logroot@172.26.37.161's password: WARNING: this command line interface is deprecated and will disappear, start using the new one as described with '--new --help'.Warning: Local version 2.0.5 does not match remote version 2.2.4.Deleting increment at time:Thu Apr 20 21:56:26 2023# rdiff-backup -l root@172.26.37.161::/backup/201_var_logroot@172.26.37.161's password: Found 1 increments:    increments.2023-04-24T16:38:50+08:00.dir   Mon Apr 24 04:38:50 2023Current mirror: Mon Apr 24 04:39:19 2023重要选项
--force:逼迫删除旧备份
--remove-older-than: 删除早于指定限期的备份
4.备份履历查抄

1)检察汗青记载
# rdiff-backup -l backup-dir/file# rdiff-backup --list-increments backup-dir/fileeg:
# rdiff-backup --list-increments root@172.26.37.161::/backup/201_var_logroot@172.26.37.161's password: Found 1 increments:    increments.2023-04-24T16:38:50+08:00.dir   Mon Apr 24 04:38:50 2023Current mirror: Mon Apr 24 04:39:19 2023重要选项
--list-increments:检察汗青记载
5.备份自动化

※当地服务器的目次备份到其他服务器,须要密钥认证。
如果想要自动化备份,制作备份脚本并用cron举行管理
eg:
①新建自动化脚本
# vi /home/test/rdiff-backup-test.sh        ##!/bin/bash    rdiff-backup  /var/log/ root@172.26.37.161::/backup/201_var_log②自动化脚本赋予权限
# chmod +x /home/test/rdiff-backup-test.sh③设置crontab定时使命
每天破晓2点实验备份操持# crontab -e0 2 * * * /home/test/rdiff-backup-test.sh > /dev/null
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 16:48, Processed in 0.122073 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表