plc-mirror/csv_export.sh

55 lines
2.3 KiB
Bash
Raw Normal View History

2024-02-19 20:06:16 +01:00
#!/bin/sh
set -e
# ------------------------------ Write data timestamp ----------------------------------
echo "export_start" > timestamp.csv
date -Iseconds --utc >> timestamp.csv
# ------------------------------ Refresh views ----------------------------------
docker compose exec -iT postgres psql -U postgres -d bluesky <<- EOF
\timing
\echo Refreshing follows...
refresh materialized view export_follows;
\echo Refreshing like counts...
refresh materialized view export_likes;
\echo Refreshing reply counts...
refresh materialized view export_replies;
\echo Refreshing block list...
refresh materialized view export_blocks;
\echo Refreshing DID list...
refresh materialized view export_dids;
2024-02-19 20:06:16 +01:00
EOF
2024-02-20 20:07:47 +01:00
# ------------------------------ Dump views into .csv ----------------------------------
2024-02-20 20:07:47 +01:00
echo "Writing .csv files..."
2024-02-19 20:06:16 +01:00
docker compose exec -it postgres psql -U postgres -d bluesky \
-c "copy (select * from export_follows) to stdout with csv header;" > follows.csv
2024-02-19 20:06:16 +01:00
docker compose exec -it postgres psql -U postgres -d bluesky \
-c "copy (select * from export_likes) to stdout with csv header;" > like_counts.csv
docker compose exec -it postgres psql -U postgres -d bluesky \
-c "copy (select * from export_replies) to stdout with csv header;" > post_counts.csv
docker compose exec -it postgres psql -U postgres -d bluesky \
-c "copy (select * from export_blocks) to stdout with csv header;" > blocks.csv
docker compose exec -it postgres psql -U postgres -d bluesky \
-c "copy (select * from export_dids) to stdout with csv header;" > dids.csv
2024-02-20 20:07:47 +01:00
# ------------------------------ Free up space used by materialized views ----------------------------------
2024-02-20 20:07:47 +01:00
docker compose exec -iT postgres psql -U postgres -d bluesky <<- EOF
\timing
refresh materialized view export_follows with no data;
refresh materialized view export_likes with no data;
refresh materialized view export_replies with no data;
refresh materialized view export_blocks with no data;
refresh materialized view export_dids with no data;
2024-02-20 16:36:52 +01:00
EOF
# ------------------------------ Dump handles from plc-mirror ----------------------------------
2024-02-20 16:36:52 +01:00
2024-02-28 19:37:18 +01:00
docker exec -t plc-postgres-1 psql -U postgres -d plc \
-c 'copy (select handle, did as "did:ID" from actors) to stdout with (format csv , header, force_quote ("handle"));' | sed -E -e 's/([^\\])\\",/\1\\\\",/g' > handles.csv