-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·57 lines (53 loc) · 1.71 KB
/
init.sh
File metadata and controls
executable file
·57 lines (53 loc) · 1.71 KB
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
#!/bin/busybox ash
#
# Script to init DB.
. "${0%/*}/common.sh"
mkdir -p "$BACKUP_CURRENT" "$BACKUP_MAIN" "$BACKUP_TMP" "$BACKUP_RSYNC_LOGS" "$BACKUP_RSYNC_STATS" "$PARTIAL_DIR"
test "$1" = "--notable" || echo "
DROP TABLE IF EXISTS history;
PRAGMA journal_mode=WAL;
CREATE TABLE history(
inode INTEGER,
type TEXT,
dirname TEXT,
filename TEXT,
created TEXT,
deleted TEXT,
freq INTEGER AS (
CASE
WHEN deleted = '$BACKUP_TIME_NOW'
THEN 0 -- not deleted yet
WHEN strftime('%Y-%m', created, '-1 second') !=
strftime('%Y-%m', deleted, '-1 second')
THEN 1 -- different month
WHEN strftime('%Y %W', created, '-1 second') !=
strftime('%Y %W', deleted, '-1 second')
THEN 5 -- different week
WHEN strftime('%Y-%m-%d', created, '-1 second') !=
strftime('%Y-%m-%d', deleted, '-1 second')
THEN 30 -- different day
WHEN strftime('%Y-%m-%d %H', created, '-1 second') !=
strftime('%Y-%m-%d %H', deleted, '-1 second')
THEN 720 -- different hour
WHEN strftime('%s', created, '-1 second')/$BACKUP_MAX_FREQ_SEC !=
strftime('%s', deleted, '-1 second')/$BACKUP_MAX_FREQ_SEC
THEN $BACKUP_MAX_FREQ -- crosses BACKUP_MAX_FREQ boundary (usually 5 minutes)
ELSE 2592000 / (strftime('%s', deleted) - strftime('%s', created))
-- 2592000 is number of seconds per month
END
) STORED
);
DROP TABLE IF EXISTS bad_new_files;
CREATE TABLE bad_new_files(
inode INT,
type TEXT,
dirname TEXT,
filename TEXT,
created TEXT,
deleted TEXT
);
" | $SQLITE
test "$1" = "--noindex" || echo "
CREATE UNIQUE INDEX history_update ON history(dirname, filename) WHERE freq = 0;
CREATE INDEX timeline ON history(freq, deleted) WHERE freq != 0;
" | $SQLITE