update_akkoma.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. # update backend
  27. su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl update --branch stable" && su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl migrate"
  28. # start akkoma
  29. systemctl start $AKKOMA_SERVICE
  30. # wait for startup
  31. sleep 4s
  32. # update frontend
  33. su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl frontend install pleroma-fe --ref stable" && su $AKKOMA_USER -s $SHELL -lc "./bin/pleroma_ctl frontend install admin-fe --ref stable"
  34. # upload archive
  35. rclone copy $BACKUP_PATH.tar.gz.gpg od-1:/upload -vP
  36. # clean up
  37. rm $BACKUP_PATH.tar.gz.gpg