File: backup.result

package info (click to toggle)
tarantool 1.9.1.26.g63eb81e3c-1.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 38,724 kB
  • sloc: ansic: 247,425; cpp: 24,952; sh: 17,809; python: 10,699; makefile: 2,682
file content (161 lines) | stat: -rw-r--r-- 3,600 bytes parent folder | download
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
fio = require 'fio'
---
...
log = require 'log'
---
...
test_run = require('test_run').new()
---
...
test_run:cleanup_cluster()
---
...
-- Make sure that garbage collection is disabled
-- while backup is in progress.
default_checkpoint_count = box.cfg.checkpoint_count
---
...
box.cfg{checkpoint_count = 1}
---
...
ENGINES = {'memtx', 'vinyl'}
---
...
-- Directories where files can be stored,
-- from longest to shortest.
CFG_DIRS = {box.cfg.wal_dir, box.cfg.memtx_dir, box.cfg.vinyl_dir}
---
...
table.sort(CFG_DIRS, function(a, b) return #a > #b end)
---
...
-- Create and populate tables. Make a snapshot to backup.
_ = test_run:cmd("setopt delimiter ';'")
---
...
for _, engine in ipairs(ENGINES) do
    s = box.schema.space.create(engine, {engine=engine})
    _ = s:create_index('pk')
    for i=1,3 do s:insert{i, engine..i} end
end
box.snapshot()
_ = test_run:cmd("setopt delimiter ''");
---
...
-- Add more data, but don't make a snapshot.
-- These data won't make it to the backup.
_ = test_run:cmd("setopt delimiter ';'")
---
...
for _, engine in ipairs(ENGINES) do
    s = box.space[engine]
    for i=1,3 do s:insert{i*10} end
end
_ = test_run:cmd("setopt delimiter ''");
---
...
-- Start backup.
files = box.backup.start()
---
...
box.backup.start() -- error: backup is already in progress
---
- error: Backup is already in progress
...
-- Make sure new snapshots are not included into an ongoing backups.
_ = test_run:cmd("setopt delimiter ';'")
---
...
-- Even though checkpoint_count is set to 1, this must not trigger
-- garbage collection, because the checkpoint is pinned by backup.
for _, engine in ipairs(ENGINES) do
    s = box.space[engine]
    for i=1,3 do s:insert{i*100} end
end
box.snapshot()
_ = test_run:cmd("setopt delimiter ''");
---
...
-- Prepare backup directory
backup_dir = fio.pathjoin(fio.cwd(), 'backup')
---
...
_ = os.execute(string.format('rm -rf %s', backup_dir))
---
...
log.info(string.format('save backup to %s', backup_dir))
---
...
-- Copy files to the backup directory
_ = test_run:cmd("setopt delimiter ';'")
---
...
for _, path in ipairs(files) do
    suffix = string.gsub(path, '.*%.', '')
    if suffix == 'xlog' then
        dir = box.cfg.wal_dir
    elseif suffix == 'snap' then
        dir = box.cfg.memtx_dir
    elseif suffix == 'vylog' or suffix == 'run' or suffix == 'index' then
        dir = box.cfg.vinyl_dir
    end
    assert(dir ~= nil)
    rel_path = string.sub(path, string.len(dir) + 2)
    dest_dir = fio.pathjoin(backup_dir, fio.dirname(rel_path))
    log.info(string.format('copy %s', rel_path))
    os.execute(string.format('mkdir -p %s && cp %s %s', dest_dir, path, dest_dir))
end
_ = test_run:cmd("setopt delimiter ''");
---
...
box.backup.stop()
---
...
-- Check that we can restore from the backup.
_ = test_run:cmd(string.format("create server copy with script='box/backup_test.lua', workdir='%s'", backup_dir))
---
...
_ = test_run:cmd("start server copy")
---
...
_ = test_run:cmd('switch copy')
---
...
box.space['memtx']:select()
---
- - [1, 'memtx1']
  - [2, 'memtx2']
  - [3, 'memtx3']
...
box.space['vinyl']:select()
---
- - [1, 'vinyl1']
  - [2, 'vinyl2']
  - [3, 'vinyl3']
...
_ = test_run:cmd('switch default')
---
...
_ = test_run:cmd("stop server copy")
---
...
_ = test_run:cmd("cleanup server copy")
---
...
-- Check that backup still works.
_ = box.backup.start()
---
...
box.backup.stop()
---
...
-- Cleanup.
_ =  os.execute(string.format('rm -rf %s', backup_dir))
---
...
for _, engine in ipairs(ENGINES) do box.space[engine]:drop() end
---
...
box.cfg{checkpoint_count = default_checkpoint_count}
---
...