backup_akkoma.sh 917 B

12345678910111213141516171819202122232425262728293031
  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. # stop akkoma
  15. systemctl stop $AKKOMA_SERVICE
  16. # backup database/config.exs/static files
  17. cd $AKKOMA_PATH
  18. su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl config dump" > $AKKOMA_DBCONFIG_PATH
  19. sed -i 's/\r//g' $AKKOMA_DBCONFIG_PATH
  20. sudo -Hu postgres pg_dump -d $AKKOMA_DB --format=custom -f $BACKUP_PATH/akkoma.pgdump
  21. 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
  22. # upload archive
  23. rclone copy /home/plbk/akbk+*.tar.gz.gpg od-1:/upload -vP
  24. # start akkoma
  25. systemctl start $AKKOMA_SERVICE