From 6debb31452cfba186c5b6cf4092d5c26b9413fc7 Mon Sep 17 00:00:00 2001 From: Cedric Fung Date: Sat, 12 Aug 2023 08:23:50 +0000 Subject: [PATCH] backup script for kernel snapshots to s3 --- config/backup.service | 13 +++++++++++++ config/backup.timer | 11 +++++++++++ config/config.example.toml | 4 +++- config/config_test.go | 3 +++ config/{systemd.service => kernel.service} | 0 config/snapshots.sh | 13 +++++++++++++ storage/badger.go | 2 +- 7 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 config/backup.service create mode 100644 config/backup.timer rename config/{systemd.service => kernel.service} (100%) create mode 100644 config/snapshots.sh diff --git a/config/backup.service b/config/backup.service new file mode 100644 index 000000000..654bde14c --- /dev/null +++ b/config/backup.service @@ -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 diff --git a/config/backup.timer b/config/backup.timer new file mode 100644 index 000000000..6580bd510 --- /dev/null +++ b/config/backup.timer @@ -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 diff --git a/config/config.example.toml b/config/config.example.toml index 5e35a3193..e9b9c7c1c 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -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] diff --git a/config/config_test.go b/config/config_test.go index ceaad147e..589c9d62e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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]) diff --git a/config/systemd.service b/config/kernel.service similarity index 100% rename from config/systemd.service rename to config/kernel.service diff --git a/config/snapshots.sh b/config/snapshots.sh new file mode 100644 index 000000000..0e874d0a2 --- /dev/null +++ b/config/snapshots.sh @@ -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 diff --git a/storage/badger.go b/storage/badger.go index 7fab7a000..7a73f211e 100644 --- a/storage/badger.go +++ b/storage/badger.go @@ -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)