{"id":13425071,"url":"https://github.com/nndi-oss/pg_reloaded","last_synced_at":"2025-03-15T19:32:35.119Z","repository":{"id":46279003,"uuid":"192100069","full_name":"nndi-oss/pg_reloaded","owner":"nndi-oss","description":"A simple tool to help administrators restore PostgreSQL databases periodically","archived":true,"fork":false,"pushed_at":"2021-11-02T17:30:52.000Z","size":76,"stargazers_count":54,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-16T03:14:45.600Z","etag":null,"topics":["database","golang","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nndi-oss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-15T16:25:44.000Z","updated_at":"2024-01-03T14:16:26.000Z","dependencies_parsed_at":"2022-09-24T14:12:31.148Z","dependency_job_id":null,"html_url":"https://github.com/nndi-oss/pg_reloaded","commit_stats":null,"previous_names":["zikani03/pg_reloaded"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nndi-oss%2Fpg_reloaded","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nndi-oss%2Fpg_reloaded/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nndi-oss%2Fpg_reloaded/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nndi-oss%2Fpg_reloaded/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nndi-oss","download_url":"https://codeload.github.com/nndi-oss/pg_reloaded/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243781828,"owners_count":20347155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","golang","postgresql"],"created_at":"2024-07-31T00:01:03.879Z","updated_at":"2025-03-15T19:32:34.849Z","avatar_url":"https://github.com/nndi-oss.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"logo.svg\" alt=\"PG Reloaded logo\" height=\"128px\" \u003e\r\n\u003c/p\u003e\r\n\r\nPG Reloaded\r\n===\r\n\r\n`pg_reloaded` is a program that's useful for restoring databases. You can use it to refresh databases for online demos, development databases and anywhere where you may want to reset the data after use. You schedule your databases to be restored from a backup. \r\n\r\n## Installation\r\n\r\nCurrently, you will have to build it from source, binary Releases will be made available soon.\r\n\r\n## Usage\r\n\r\nGet the usage information by running `pg_reloaded --help`\r\n\r\n```sh\r\n$ pg_reloaded check --config=\"pg_reloaded.yml\"\r\n\r\n# Run with the default configuration\r\n$ pg_reloaded start\r\n\r\n# Or with a path to a configuration file\r\n$ pg_reloaded start --config=\"development.yml\" --log-file=\"./path/to/log\"\r\n```\r\n\r\nIf you would like to restore a database immediately, run the following:\r\n\r\n```sh\r\n$ pg_reloaded run \"database\"\r\n```\r\n\r\nIn order to be effective, `pg_reloaded` needs to run in the background as a daemon.\r\nThere's a sample [Systemd Unit File here](./config/pg_reloaded.service).\r\n\r\nYou can also use supervisor to run the `pg_reloaded` daemon, below is an example\r\nconfiguration for [Supervisor](https://github.com/supervisor/supervisor)\r\n\r\n```ini\r\n[program:pg_reloaded]\r\ncommand=/usr/bin/pg_reloaded start --config=/etc/pg_reloaded/pg_reloaded.yml\r\n```\r\n\r\nPlease note that these process management systems must be configured to \r\nstart pg_reloaded on boot for best effective use of the scheduling capabilities.\r\n\r\n## Example configuration\r\n\r\nPG Reloaded is configured via YAML configuration file which records the details\r\nabout how and when to restore your databases.\r\n\r\nBy default `pg_reloaded` reads configuration from a file named `pg_reloaded.yml`\r\nin the home directory if present i.e. `$HOME/pg_reloaded.yml`\r\n(on Windows in `%UserProfile%\\pg_reloaded.yml`)\r\n\r\nYou can specify a path for the configuration file via the `--config` option\r\non the command-line.\r\n\r\nThe configuration basically looks like the following:\r\n\r\n```yaml\r\n# Absolute path to the directory containing postgresql client programs\r\n# The following client programs are searched for specifically:\r\n# psql, pg_restore, pg_dump\r\npsql_path: \"/path/to/psql-dir\"\r\n# Absolute path to the logfile, will be created if it does not exist\r\nlog_file: \"/path/to/logfile\"\r\nservers:\r\n  # name - A name to identify the server in the \"databases\" section of the configuration\r\n  - name: \"my-development-server\"\r\n    # host - The host for the database\r\n    host: \"localhost\"\r\n    # port - The port for the database\r\n    port: 5432\r\n    # Username for the user must have CREATE DATABASE \u0026 DROP DATABASE privileges\r\n    username: \"appuser\" \r\n    # Password for the user role on the database \r\n    password: \"password\"\r\ndatabases:\r\n  # name - The database name \r\n  - name: \"my_database_name\"\r\n    # server - The name of a server in the \"servers\" list\r\n    server: \"my-development-server\"\r\n    # schedule - Specifies the schedule for running the database restores in\r\n    # daemon mode. Supports simple interval notation and CRON expressions\r\n    schedule: \"@every 24h\"\r\n    # Source specifies where to get the schema and data to restore  \r\n    source:\r\n      # The type of file(s) to restore the database from.\r\n      # The following types are (will be) supported:\r\n      #\r\n      # * sql - load schema \u0026 data from SQL files using psql\r\n      # * tar - load schema \u0026 data from SQL files using pg_restore\r\n      # * csv - load data from CSV files using pgfutter\r\n      # * json - load data from JSON files using pgfutter\r\n      type: \"sql\"\r\n      \r\n      # The absolute path to the file to restore the database from \r\n      file: \"/path/to/file\"\r\n      \r\n      # The absolute path to the schema file to be used to create tables, functions etc..\r\n      # Schema MUST be specified if source type is one of: csv, json \r\n      # or if the SQL file only contains data\r\n      schema: \"/path/to/schema/file.sql\"\r\n```\r\n\r\n### Supported notation for Scheduling\r\n\r\nThe real value of pg_reloaded is in its ability to restore databases according\r\nto a schedule. \r\n\r\nThe following syntax is supported for scheduling\r\n\r\n* Intervals: Simple interval notation is supported. Only for seconds(`s`), \r\nminutes (`m`) and hours (`h`). \r\n\r\ne.g. `@every 10m`, `@every 2h`, `@weekly`, `@monthly`\r\n\r\n* CRON Expression: Most CRON expressions valid [here](http://crontab.guru) should be valid\r\n\r\n\r\n## Prerequisites\r\n\r\n* The postgresql client programs must be present on your path or configured in \r\nthe config file or command-line for `pg_reloaded` to work. In particular the \r\nprogram may need to execute `psql`, `pg_restore` or `pg_dump` during it's operation.\r\n\r\nIn the YAML file:\r\n\r\n```yaml\r\npsql_path: \"/path/to/psql-dir/\"\r\n```\r\n\r\nOn the command-line\r\n\r\n```sh\r\n$ pg_reloaded --psql-path=\"/path/to/psql-dir\" \r\n```\r\n\r\n### Supported Sources\r\n\r\nCurrently, the only supported sources are:\r\n\r\n* *SQL* via dumped *SQL file* - default source, load dumps/data files from the filesystem\r\n\r\n## Docker\r\n\r\nYou can build Docker images/containers using the [Dockerfile](./Dockerfile).\r\nAt this time, you can pull images from [@gkawamoto's](https://github.com/gkawamoto) Dockerhub:\r\n\r\n```\r\n$ docker pull gkawamoto/pg_reloaded\r\n```\r\n\r\n## Building from Source\r\n\r\nI encourage you to build pg_reloaded from source, if only to get you to try out\r\nGo ;). So the first step is to Install Go.\r\n\r\nThe next step is to clone the repo and then after that, building the binary _should_\r\nbe as simple as running `go build`\r\n\r\n```sh\r\n$ git clone https://github.com/nndi-oss/pg_reloaded.git\r\n$ cd pg_reloaded\r\n$ go build -o dist/pg_reloaded\r\n```\r\n\r\n### Dependencies\r\n\r\nThis project could not be made possible without these great Open-Source \r\ntools and their authors/contributors whose shoulders are steady enough to stand on:\r\n\r\n* [Go 1.12.x](https://golang.org)\r\n* [Postgresql (Ofcourse!)](https://postgresql.org)\r\n* [cobra](https://github.com/spf13/cobra)\r\n* [viper](https://github.com/spf13/viper)\r\n* The [cron](./cron) package is copied from [dkron](https://github.com/victorcoder/dkron/tree/master/cron)\r\n\r\n## CHENJEZO ( *Notice* )\r\n\r\n- **Running as a Service on Windows**\r\n\r\nSince you have to run it in the background for the scheduling functionality to be\r\nof any value a Service wrapper would be ideal on Windows - but until then you will have \r\nto run it in the foreground.\r\n\r\n- **BE CAREFULL, IT MAY EAT YOUR LUNCH!**\r\n\r\nThis is not meant to be run on *production* databases which house critical data\r\nthat you can't afford to lose. It's meant for demo and development databases that\r\ncan be dropped and restored without losing a dime. Use good judgment.\r\n\r\n\r\n## ROADMAP\r\n\r\nSome rough ideas on how to take this thing further:\r\n\r\n* Add preload and post-load conditions for databases\r\n\r\n```yaml\r\npreload:\r\n  dump: true\r\n  checkActivity: true\r\npostload:\r\n  notify: true\r\n```\r\n\r\n* Backup the current database before restoring using pg_dump or [pgclimb](https://github.com/lukasmartinelli/pgclimb)\r\n* A Windows Service wrapper\r\n* Add support for the following sources:\r\n\r\n  * *csv* : loads data from CSV files, just like you would with [pgfutter](https://github.com/lukasmartinelli/pgfutter)\r\n  * *json*: loads data from JSON files, just like you would with pgfutter\r\n  * *postgres* - load database from a remote postgresql database\r\n  * *http* - load a database dump from an HTTP server\r\n  * *s3* - load database dump from AWS S3\r\n\r\n## CONTRIBUTING\r\n\r\nIssues and Pull Requests welcome.\r\n\r\n## License\r\n\r\nMIT License\r\n\r\n---\r\n\r\nCopyright (c) 2019 - 2020, NNDI \r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnndi-oss%2Fpg_reloaded","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnndi-oss%2Fpg_reloaded","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnndi-oss%2Fpg_reloaded/lists"}