Skip to content

Commit

Permalink
refactor: update archive-mysql script
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakia committed Jan 9, 2024
1 parent b3eea4a commit 914c581
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
15 changes: 15 additions & 0 deletions config.sample.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ export const mysql = {
}
}

export const storage_mysql = {
client: 'mysql',
connection: {
host: 'localhost',
user: 'root',
password: '',
database: 'nano_development',
charset: 'utf8mb4'
},
pool: {
min: 2,
max: 20
}
}

export const nanodbAPI = ''
export const trustedAddresses = []
export const rpcAddresses = []
Expand Down
21 changes: 20 additions & 1 deletion scripts/archive-mysql.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import fs from 'fs'
import { exec } from 'child_process'
import { createObjectCsvWriter as createCsvWriter } from 'csv-writer'
import dayjs from 'dayjs'
import Knex from 'knex'

import db from '#db'
import { isMain } from '#common'
import * as config from '#config'

const storage_mysql = Knex(config.storage_mysql)

const execp = util.promisify(exec)
const logger = debug('archive')

const dir = '/root/archives'
const dir = '/home/user/nano-community-archives'

const zip = async ({ gzFilename, csvFilename }) => {
logger(`creating zip of ${csvFilename}`)
Expand Down Expand Up @@ -48,6 +52,12 @@ const archiveRepresentativesUptime = async () => {
return
}

await storage_mysql('representatives_uptime')
.insert(rows)
.onConflict()
.merge()
logger(`copied ${rows.length} rows to storage_mysql`)

logger(`archving ${rows.length} representatives_uptime entries`)
const filename = `representatives-uptime-archive_${timestamp}`
const csvFilename = `${filename}.csv`
Expand Down Expand Up @@ -85,6 +95,12 @@ const archiveRepresentativesTelemetry = async () => {
return
}

await storage_mysql('representatives_telemetry')
.insert(rows)
.onConflict()
.merge()
logger(`copied ${rows.length} rows to storage_mysql`)

logger(`archving ${rows.length} representatives_telemetry entries`)
const filename = `representatives-telemetry-archive_${timestamp}`
const csvFilename = `${filename}.csv`
Expand Down Expand Up @@ -142,6 +158,9 @@ const archivePosts = async () => {
return
}

await storage_mysql('posts').insert(posts).onConflict().merge()
logger(`copied ${posts.length} rows to storage_mysql`)

logger(`archving ${posts.length} posts`)
const filename = `posts-archive_${timestamp}`
const csvFilename = `${filename}.csv`
Expand Down
1 change: 0 additions & 1 deletion server/crontab
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

## backup mysql
0 0 * * 0 /bin/bash /root/nano-community/scripts/backup-mysql.sh -f &>> /var/log/nano-community/backup-mysql-full.log
0 1 * * 0 NODE_ENV=production /root/.nvm/versions/node/v14.17.0/bin/node /root/nano-community/scripts/archive-mysql.mjs &>> /var/log/nano-community/archive-mysql.log

## rollups
0 0 * * * NODE_ENV=production /root/.nvm/versions/node/v14.17.0/bin/node /root/nano-community/scripts/rollup-uptime.mjs --days 2 &>> /var/log/nano-community/rollup-uptime.log
Expand Down

0 comments on commit 914c581

Please sign in to comment.