'Pruning PostgreSQL Tables and Store in JSON files

For my Django application I am using PostgreSQL and there are tables to store log entries such as Webhook events, email logs etc. I would like to keep these event logs only for 30 days and move the older logs to JSON file stored in Google Storage Bucket. Is there any recommended way to do this operation on a periodic basis? Essentially I would like to prune old records and store them in a JSON file periodically.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source