backup_akkoma.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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/config.exs/static files
  23. sudo -Hu postgres pg_dump -d $AKKOMA_DB --format=custom -f $BACKUP_PATH/akkoma.pgdump
  24. tar -czpPf - $AKKOMA_STATIC_PATH $AKKOMA_CONFIG_PATH $BACKUP_PATH | gpg -e -r 0 > $BACKUP_PATH.tar.gz.gpg
  25. rm -r $BACKUP_PATH
  26. # start akkoma
  27. systemctl start $AKKOMA_SERVICE
  28. # upload archive
  29. rclone copy $BACKUP_PATH.tar.gz.gpg od-1:/upload -vP
  30. # clean up
  31. rm $BACKUP_PATH.tar.gz.gpg