section 01 a website

Mastodonの自動アーカイブ

18:30, July 12 2023

ただのtech memo。

リンク

背景

@[email protected] は3ヶ月で自動post削除をするようにしているが、アカシックレコードとしてTwitter-likeなものを使ってきたので同様の性質は欲しい。

mastodon-archiveを入れる

pip3を動かせるようにするまでの手順は省略1

pip3 install --user mastodon-archive

archive.sh

#!/bin/bash

today=$(date +"%Y%m%d")

mastodon-archive archive [email protected]
mv mstdn.cryptic-command.net.user.s01.json "s01-$today.json"

systemdのUser TimerとUser Serviceを設定する

~/.config/systemd/user/mstdn-archive.timer

[Unit]
Description=Archive mstdn.cryptic-command.net posts
Requires=mstdn-archive.service

[Timer]
Unit=mstdn-archive.service
OnCalendar=Sun 00:00

[Install]
WantedBy=timers.target

(8/5更新: どのserviceを実行するべきかの記述が必要だった。これがないとタイマーは発火するけど何もしない。)

~/.config/systemd/user/mstdn-archive.service

[Unit]
Description=service for mstdn archive

[Service]
Environment="PATH=/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
Type=oneshot
WorkingDirectory=/home/ubuntu/mstdn-archive
ExecStart=/bin/bash /home/ubuntu/mstdn-archive/archive.sh

その後

systemctl --user daemon-reload
systemctl --user enable mstdn-archive.timer
systemctl --user start mstdn-archive.timer
systemctl --user start mstdn-archive.service # run the contents of the timer manually
journalctl --user -xeu mstdn-archive.service # check log
  1. 私はピュトーンをそんなに使わないので実はここもハマりどころではあるんだが…