Skip to content

Commit

Permalink
backup script for kernel snapshots to s3
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Aug 12, 2023
1 parent e888c51 commit 6debb31
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
13 changes: 13 additions & 0 deletions config/backup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Mixin Kernel Backup Service
After=network.target

[Service]
User=one
Type=simple
ExecStart=/user/bin/mnm run '/home/one/bin/snapshots.sh'
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
11 changes: 11 additions & 0 deletions config/backup.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Mixin Kernel Backup Timer

[Timer]
Unit=mixin-backup.service
OnCalendar=*-*-* 00:00:00
Persistent=True
RandomizedDelaySec=300

[Install]
WantedBy=timers.target
4 changes: 3 additions & 1 deletion config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ cache-ttl = 7200
[storage]
# enable badger value log gc will reduce disk storage usage
value-log-gc = true
# compaction level should be increased when data too big can badger panic
# max levels should be increased when data too big and badger panic
# increase the level to 8 when data grows big to execeed 16TB
# the max levels can not be decreased once up, so be cautious
max-compaction-levels = 7

[network]
Expand Down
3 changes: 3 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func TestConfig(t *testing.T) {
require.Equal(4096, custom.Node.MemoryCacheSize)
require.Equal(7200, custom.Node.CacheTTL)

require.Equal(true, custom.Storage.ValueLogGC)
require.Equal(7, custom.Storage.MaxCompactionLevels)

require.Equal("mixin-node.example.com:7239", custom.Network.Listener)
require.Len(custom.Network.Peers, 26)
require.Equal("lehigh-2.hotot.org:7239", custom.Network.Peers[25])
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions config/snapshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

sudo systemctl stop mixin-archive || exit 1

tar cf - -C /mnt/archive/mixin snapshots | s3cmd put - s3://mixin/snapshots/kernel.tar.new || exit 1

s3cmd mv s3://mixin/snapshots/kernel.tar.new s3://mixin/snapshots/kernel.tar || exit 1

s3cmd setacl s3://mixin/snapshots/kernel.tar --acl-public || exit 1

s3cmd la --recursive || exit 1

sudo systemctl restart mixin-archive
2 changes: 1 addition & 1 deletion storage/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func openDB(dir string, sync bool, custom *config.Custom) (*badger.DB, error) {
// for level up to max levels: sum(base * (multiplier ** level))
// increase the level to 8 when data grows big to execeed 16TB
// the drawback is huge memory usage increases when 1 level up
// the max levels can be decreased once up, so be cautious
// the max levels can not be decreased once up, so be cautious
opts = opts.WithBaseLevelSize(16 << 20)
opts = opts.WithLevelSizeMultiplier(16)
opts = opts.WithMaxLevels(7)
Expand Down

0 comments on commit 6debb31

Please sign in to comment.