backup_akkoma.sh 946 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. # set vars
  3. AKKOMA_DB=pleroma
  4. AKKOMA_USER=pleroma
  5. AKKOMA_SERVICE=pleroma
  6. AKKOMA_PATH=/opt/pleroma
  7. AKKOMA_STATIC_PATH=/var/lib/pleroma
  8. AKKOMA_CONFIG_PATH=/etc/pleroma/config.exs
  9. AKKOMA_DBCONFIG_PATH=/tmp/config_db.exs
  10. BACKUP_PATH=/home/plbk
  11. # clean up
  12. rm $BACKUP_PATH/*
  13. rm $AKKOMA_DBCONFIG_PATH
  14. # export config in database
  15. cd $AKKOMA_PATH
  16. su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl config dump" > $AKKOMA_DBCONFIG_PATH
  17. sed -i 's/\r//g' $AKKOMA_DBCONFIG_PATH
  18. # stop akkoma
  19. systemctl stop $AKKOMA_SERVICE
  20. # backup database/config.exs/static files
  21. sudo -Hu postgres pg_dump -d $AKKOMA_DB --format=custom -f $BACKUP_PATH/akkoma.pgdump
  22. tar -czpPf - $AKKOMA_STATIC_PATH $AKKOMA_CONFIG_PATH $BACKUP_PATH/akkoma.pgdump $AKKOMA_DBCONFIG_PATH | gpg -e -r 0 > $BACKUP_PATH/akbk+$(date +%Y%m%d-%H%M%S).tar.gz.gpg
  23. # start akkoma
  24. systemctl start $AKKOMA_SERVICE
  25. # upload archive
  26. rclone copy /home/plbk/akbk+*.tar.gz.gpg od-1:/upload -vP