backup_akkoma.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. # set vars
  3. BACKUP_ROOT_PATH=/tmp
  4. DATE=$(date +%Y%m%d-%H%M%S)
  5. BACKUP_NAME=akbk-$DATE
  6. BACKUP_PATH=$BACKUP_ROOT_PATH/$BACKUP_NAME
  7. mkdir -p $BACKUP_PATH
  8. chmod a+w $BACKUP_PATH
  9. AKKOMA_DB=pleroma
  10. AKKOMA_USER=pleroma
  11. AKKOMA_SERVICE=pleroma
  12. AKKOMA_PATH=/opt/pleroma
  13. AKKOMA_STATIC_PATH=/var/lib/pleroma
  14. AKKOMA_CONFIG_PATH=/etc/pleroma/config.exs
  15. AKKOMA_DBCONFIG_PATH=$BACKUP_PATH/config_db.exs
  16. # export config in database
  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. # stop akkoma
  21. systemctl stop $AKKOMA_SERVICE
  22. # backup database
  23. sudo -Hu postgres pg_dump -d $AKKOMA_DB --format=custom -f $BACKUP_PATH/akkoma.pgdump
  24. # start akkoma in background
  25. nohup systemctl start $AKKOMA_SERVICE >&/dev/null &
  26. # backup config.exs/static files
  27. tar -czpPf - $AKKOMA_STATIC_PATH $AKKOMA_CONFIG_PATH $BACKUP_PATH | gpg -e -r 0 > $BACKUP_PATH.tar.gz.gpg
  28. rm -r $BACKUP_PATH
  29. # upload archive
  30. rclone copy $BACKUP_PATH.tar.gz.gpg od-1:/upload -vP
  31. # clean up
  32. rm $BACKUP_PATH.tar.gz.gpg