1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| # 创建仓库存储目录 $ mkdir -p /opt/backup/
# 新建仓库 $ borg init --encryption=repokey /opt/backup/borg_sample
# 创建测试备份内容 # 会被修改的文件file_change.txt,不会被修改的文件file_static.txt,二进制大文件random.dump $ mkdir -p /opt/data $ cd /opt/data $ echo "here is the first line of file 1" >> file_change.txt $ echo "here is the static file" >> file_static.txt $ dd if=/dev/urandom of=random.dump bs=10M count=10 10+0 records in 10+0 records out 104857600 bytes (105 MB) copied, 0.950948 s, 110 MB/s $
# 第一次备份 $ borg create --stats /opt/backup/borg_sample::first /opt/data/ ------------------------------------------------------------------------------ Archive name: first Archive fingerprint: 92bf20bca7a1d620d92f831e763601ca63ff951944de81146332ad12e93bb787 Time (start): Tue, 2019-09-24 04:06:51 Time (end): Tue, 2019-09-24 04:06:52 Duration: 0.82 seconds Number of files: 3 Utilization of max. archive size: 0% ------------------------------------------------------------------------------ Original size Compressed size Deduplicated size This archive: 104.86 MB 105.27 MB 105.27 MB All archives: 104.86 MB 105.27 MB 105.27 MB
Unique chunks Total chunks Chunk index: 48 48 ------------------------------------------------------------------------------ $
# 修改备份内容,修改file_change.txt, 新增file_new.txt,新增random_2.dump $ cd /opt/data $ echo "here is the second line of file 1" >> file_change.txt $ echo "here is new file for second backup" >> file_new.txt $ dd if=/dev/urandom of=random_2.dump bs=10M count=10
10+0 records in 10+0 records out 104857600 bytes (105 MB) copied, 0.599837 s, 175 MB/s $
# 第二次备份 $ borg create --stats /opt/backup/borg_sample::second /opt/data/ ------------------------------------------------------------------------------ Archive name: second Archive fingerprint: a423a94e8a8f4352e72c0951e6a408f4f4f6d5f362518dcbcba77b9005dafa12 Time (start): Tue, 2019-09-24 04:10:55 Time (end): Tue, 2019-09-24 04:10:56 Duration: 1.26 seconds Number of files: 5 Utilization of max. archive size: 0% ------------------------------------------------------------------------------ Original size Compressed size Deduplicated size This archive: 209.72 MB 210.55 MB 105.28 MB All archives: 314.58 MB 315.82 MB 210.55 MB
Unique chunks Total chunks Chunk index: 92 137 ------------------------------------------------------------------------------ $
# 列出所有的备份 $ borg list /opt/backup/borg_sample/
first Tue, 2019-09-24 04:06:51 [92bf20bca7a1d620d92f831e763601ca63ff951944de81146332ad12e93bb787] second Tue, 2019-09-24 04:10:55 [a423a94e8a8f4352e72c0951e6a408f4f4f6d5f362518dcbcba77b9005dafa12] $
# 列出第一次备份的内容 $ borg list /opt/backup/borg_sample::first drwxr-xr-x root root 0 Tue, 2019-09-24 04:03:45 opt/data -rw-r--r-- root root 33 Tue, 2019-09-24 04:03:45 opt/data/file_change.txt -rw-r--r-- root root 24 Tue, 2019-09-24 04:03:45 opt/data/file_static.txt -rw-r--r-- root root 104857600 Tue, 2019-09-24 04:03:46 opt/data/random.dump $
# 将第一次备份导出, 查看file_change.txt内容,只包含第一次的内容 $ mkdir -p /opt/restore/first $ cd /opt/restore/first $ borg extract --list /opt/backup/borg_sample::first opt/data opt/data/file_change.txt opt/data/file_static.txt opt/data/random.dump $ $ cat opt/data/file_change.txt here is the first line of file 1 $
# 将第二次备份导出, 查看file_change.txt内容,其中包含了第二次新增加的内容 # 也包含了第一次新增的file_new.txt和random_2.dump $ mkdir -p /opt/restore/second $ cd /opt/restore/second $ borg extract --list /opt/backup/borg_sample::second opt/data opt/data/file_change.txt opt/data/file_static.txt opt/data/random.dump opt/data/file_new.txt opt/data/random_2.dump $ $ cat opt/data/file_change.txt here is the first line of file 1 here is the second line of file 1 $
# 第一次备份是100M,第二次是200M, 但由于是增量备份的,random.dump没有改变,因此仓库的总容量只有200M $ du -sh /opt/backup/borg_sample/ 201M /opt/backup/borg_sample/ $
# 删除第一次备份,恢复第二次的备份 # 可以看到再第一次和第二次备份中都有的file_static.txt和random.dump都可以恢复出来。 # 恢复出来的数据和之前恢复的数据是一样的 $ borg delete /opt/backup/borg_sample::first $ borg list /opt/backup/borg_sample second Tue, 2019-09-24 04:10:55 [a423a94e8a8f4352e72c0951e6a408f4f4f6d5f362518dcbcba77b9005dafa12] $ $ mkdir -p /opt/restore/second_back $ cd /opt/restore/second_back $ borg extract --list /opt/backup/borg_sample::second opt/data opt/data/file_change.txt opt/data/file_static.txt opt/data/random.dump opt/data/file_new.txt opt/data/random_2.dump $ $ diff -r /opt/restore/second /opt/restore/second_back $ $ cat opt/data/file_change.txt here is the first line of file 1 here is the second line of file 1 $ $ cat opt/data/file_static.txt here is the static file $
|