From 184f96bd4d2bb9c676210cdc45ca82343af07e44 Mon Sep 17 00:00:00 2001 From: Artyom Date: Fri, 11 Mar 2016 18:40:34 +0300 Subject: [PATCH] Backups --- INSTALL.md | 37 +++++++++++++++++++++++++++++++++++++ src/Main.hs | 6 ++++++ 2 files changed, 43 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 7fcde91..a4a211d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -64,3 +64,40 @@ exec dist/build/guide/guide And start the daemon: $ service guide start + +## Database + +If the `state/` directory doesn't exist, it will be created. However, you can get the current state of [guide.aelve.com](http://guide.aelve.com): + + $ git clone https://github.com/aelve/guide-database + $ mv guide-database state + +You can set automatic backups to your own repository, too. + +Create `.gitignore` in the `state/` folder: + +~~~ +events* +*.lock +~~~ + +Create a repository locally and remotely. If you're using Github, you can avoid having to enter passwords by generate an access token and using it as username when adding a remote: + + $ git remote add origin https://@github.com/aelve/guide-database.git + +Next, create `upload.sh`: + +~~~ +cd /root/guide/state +git add . +GIT_COMMITTER_NAME='auto' GIT_COMMITTER_EMAIL='' git commit --author="auto <>" -m "`date`" +git push +~~~ + +Finally, make a cron job that would try to upload new data every 10m (tho the actual checkpoints are only created once per hour): + + $ crontab -e + +~~~ +*/10 * * * * /root/guide/upload.sh +~~~ diff --git a/src/Main.hs b/src/Main.hs index 7f4eae4..c91ddc1 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -255,6 +255,10 @@ main :: IO () main = do bracket (openLocalStateFrom "state/" sampleState) (\db -> createCheckpoint db >> closeAcidState db) $ \db -> do + -- Create a checkpoint every hour + forkOS $ do + createCheckpoint db + threadDelay (1000000 * 3600) let config = defaultSpockCfg () PCNoDatabase db runSpock 8080 $ spock config $ do middleware (staticPolicy (addBase "static")) @@ -665,6 +669,8 @@ renderItemInfo cat item = do button "Cancel" [] $ JS.switchSection (this, "normal" :: Text) +-- TODO: use triangle icons instead of arrows [very-easy] + -- TODO: categories that don't directly compare libraries but just list all -- libraries about something (e.g. Yesod plugins, or whatever)