Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { $ } from 'zx'
- import path from "path"
- import fs from "fs"
- const backup_folder = "/vol/data/backup"
- const discord_webhook = "https://discordapp.com/api/webhooks/xxxxxx"
- process.env.BORG_PASSPHRASE = `xxxxxx`
- let now = new Date()
- let today = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}-${now.getHours()}:${now.getMinutes()}`
- console.log(today)
- if (fs.existsSync(path.join(import.meta.dirname, "temp_git"))) {
- console.log("Delete temp_git Folder")
- fs.rmdirSync(path.join(import.meta.dirname, "temp_git"), {recursive: true });
- }
- console.log("Create temp_git folder")
- fs.mkdirSync(path.join(import.meta.dirname, "temp_git"))
- console.log("")
- console.log("=== Backing Up Postgres ===")
- const sql_file = path.join(import.meta.dirname, `temp_git/dump_${today}.sql`)
- const postgres = await $`docker exec -t forgejo_db_1 pg_dumpall -c -U gitea > ${sql_file}`
- console.log("Dump OK")
- console.log("=== Add to Borg Backup ===")
- console.log("Folder: ", backup_folder)
- console.log("> Start backup")
- const borg = await $`borg create --stats ${backup_folder}::${today} ${sql_file} /vol/data/git`
- console.log("> Backup finished")
- console.log("> Start prune")
- const borg_prune = await $`borg prune ${backup_folder} --stats --list -d 7 -w 4 -m 6`
- console.log("> Prune finished")
- console.log("=== Upload Save ===")
- const rclone = await $`rclone sync ${backup_folder} swiss-backup:/git`
- console.log("=== WebHook ===")
- await fetch(discord_webhook, {
- headers: {
- 'Content-Type': 'application/json'
- },
- method: "POST",
- body: JSON.stringify({
- "username": "Backup",
- "avatar_url": undefined,
- "content": "<@xxx>",
- "embeds": [{
- title: "Backup of Git Stack finished with success",
- type: "rich",
- description: "",
- color: 0x2ecc71
- }]
- })
- })%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement