0.1.1 • Published 1 year ago

@zladuric/gts-backup v0.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

gts-backup

Backup the media for my gotosocial instance.

Warning: untested, untried (apart from my own tests), highly unstable and experimental. Use at your own peril.

Description

This project is created to help me backup my gotosocial instance. The official docs offer a few ways, but they don't work for me.

I want to do a following backup:

  • make sure my database (sqlite, yay simple stuff!) is backed up
  • make sure all the media that I have produced is backed up.

The alternatives proposed in the docs don't work for me:

  • I don't wanna clone my volume - it costs too much since I have more then just GTS there.
  • I don't wanna copy just my database because I want to keep my media that I posted.
  • I don't want to use the CLI since I also want to keep my statuses.

So I had to write my own thing.

Copying the database is easy, but which media to back up? That's what my tool is doing.

Usage

Installation

# Install this globally, then call it:
npm install -g @zladuric/gts-backup
# Alternatively npx it without installation:
npx -p @zladuric/gts-backup ...

Usage

gts-backup --username zlatko --src /mnt/data --dest /mnt/backups/gts-backup
gts-backup --username zlatko --src /mnt/data --db /mnt/gts/sqlite-other-version.db --dest /tmp/gts-backup

When you're done, just backup the top-level directory

To use this backup tool, I use a very simple filtering system: my username. I just select all media created by my account (originals and thumbnails) and copy that out there somewhere. In theory, you can just run it multiple times for multiple usernames, if you have them, but I haven't tested that.

Options:

  • username: a username to backup
  • src: where the media volume (data in your gts) is
  • db: location of the sqlite database (if not in the root of the data directory)
  • dest: the destination

Usage in your projects

So far this seems to highly experimentally und not at all safely also work if you just require the src/program.js:

[zlatko@serenity ~/projects/gts-backup]$ node
Welcome to Node.js v18.12.1.
Type ".help" for more information.
> const run = require('./src/program');
undefined
> run({ src: 'data/src', dest: 'data/dest', username: 'zlatko'});
Backing up gotosocial media. Check directory and database accesses...
Opening database...
Get the files to back  up...
select file_path,thumbnail_path from media_attachments join accounts on accounts.id = media_attachments.account_id where account_id in (select id from accounts where username like '%zlatko%')
Got the files needed for backup: 40 
Copying media...
Media copied, copying database...
Backup complete. Now tar it somewhere safe.
undefined
> 

But beware - if a file is missing or something is wrong, we call process.exit(1) explicitly.