[TOOLS] Add Make rule to delete content, but keep actors and sequences

This commit is contained in:
Hugo Sales 2022-02-28 23:37:16 +00:00
parent 43ae3add43
commit f8c1b0f71d
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -78,4 +78,27 @@ update-dependencies:
update-autocode:
docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c 'cd /var/www/social && bin/update_autocode'
backup-actors:
docker exec -it $(call translate-container-name,$(strip $(DIR))_db_1) \
sh -c 'su postgres -c "mkdir -p /tmp/backup"' && \
docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) \
sh -c "cd /var/www/social && bin/console doctrine:query:sql \"\
copy actor to '/tmp/backup/actor.csv'; copy local_user to '/tmp/backup/local_user.csv';\
copy activitypub_actor to '/tmp/backup/ap_actor.csv'; copy activitypub_rsa to '/tmp/backup/ap_rsa.csv';\
copy (SELECT 'ALTER SEQUENCE ' || c.relname || ' RESTART WITH ' || nextval(c.relname::regclass) || ';'\
FROM pg_class c WHERE c.relkind = 'S') to '/tmp/backup/sequences';\"" && \
mkdir -p /tmp/social-sql-backup && \
docker cp $(call translate-container-name,$(strip $(DIR))_db_1):/tmp/backup/. /tmp/social-sql-backup
restore-actors:
docker cp /tmp/social-sql-backup/. $(call translate-container-name,$(strip $(DIR))_db_1):/tmp/backup
docker exec -it $(call translate-container-name,$(strip $(DIR))_db_1) sh -c 'chown postgres /tmp/backup' && \
docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) \
sh -c "cd /var/www/social && bin/console doctrine:query:sql \"\
copy actor from '/tmp/backup/actor.csv'; copy local_user from '/tmp/backup/local_user.csv';\
copy activitypub_actor from '/tmp/backup/ap_actor.csv'; copy activitypub_rsa from '/tmp/backup/ap_rsa.csv';\
`cat /tmp/social-sql-backup/sequences`\""
force-nuke-everything: down remove-var remove-file up flush-redis-cache database-force-nuke install-plugins
force-delete-content: backup-actors force-nuke-everything restore-actors