{"id":26668311,"url":"https://github.com/decimoseptimo/wp-backups","last_synced_at":"2026-04-11T08:03:45.083Z","repository":{"id":200147905,"uuid":"108904468","full_name":"decimoseptimo/wp-backups","owner":"decimoseptimo","description":"Automated Wordpress backups that sync with Google drive in Ubuntu Server.","archived":false,"fork":false,"pushed_at":"2017-11-03T16:53:56.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-10-15T23:26:33.362Z","etag":null,"topics":["backup-script","backups","bash-script","google-drive","ubuntu-server","wordpress"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/decimoseptimo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-10-30T20:25:25.000Z","updated_at":"2023-10-15T23:26:37.377Z","dependencies_parsed_at":null,"dependency_job_id":"15bb8884-fdf4-42dd-a943-fae99fd0c5c1","html_url":"https://github.com/decimoseptimo/wp-backups","commit_stats":null,"previous_names":["decimoseptimo/wp-backups"],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decimoseptimo%2Fwp-backups","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decimoseptimo%2Fwp-backups/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decimoseptimo%2Fwp-backups/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decimoseptimo%2Fwp-backups/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/decimoseptimo","download_url":"https://codeload.github.com/decimoseptimo/wp-backups/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245542120,"owners_count":20632433,"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":["backup-script","backups","bash-script","google-drive","ubuntu-server","wordpress"],"created_at":"2025-03-25T20:41:44.238Z","updated_at":"2026-04-11T08:03:45.025Z","avatar_url":"https://github.com/decimoseptimo.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP Backups: Automated Wordpress backups that sync with Google drive in Ubuntu Server\nThere are wordpress plugins that handle this, but I didn't liked them for one or more of the following reasons: slower performance, full of ads, ugly UI, high update frequency with no justifiable reason or perceivable benefit, not outputting fully standalone backups.\nPlus performing this task at the OS level is more appropiate.\n\n## Requirements\n- A working wordpress application to backup\n- Wp maintenance mode plugin (see below)\n- WP CLI to activate plugins during backup\n- Grive2 for syncing backup files with google drive\n- Mysql/MariaDB\n- Ubuntu Server (tested with 16.04.3 lts)\n- Google drive account\n- User account with read/write rights to your application files\n\nNot strictly requirements:\n\n- We're assuming apache2 in the examples\n\nBy default wordpress enters maintenance mode by creating a file `.maintenance` under the aplication root, but the maintenance page is not customizable. Hence we're using a plugin that enters maintenance mode by reading a `/wp-content/wp-maintenance-mode.php` file, that's presented to the user. You have to create this file to your liking.\n\n## Documentation\n### Backup.sh\nCreates a named backup (optionally syncs files with google drive)\n\n##### Options:\n    \n    -h, --help                show brief help\n    -m, --message             log message\n    -b, --backups-path        path to backups dir (required)\n    -d, --document-root-path  path to app files (required)\n    --db-name                 app db name (required)\n    --no-sync                 bypass sync with google drive\n\n##### Example:\n```bash\n$ ~/wp-backups/backup.sh --message \"log message\" --backups-path \"~/grive/dev_backups\" --document-root-path \"/var/www/html\" --db-name \"test-db\" --no-sync\n```\nIt compress files from `/var/www/html`, exports the database `test-db`, and stores those in a child directory of `~/grive/dev_backups`. A pseudo-random auto-generated 16 alfanumeric characters string is used as the child directory and file names, and it's considered the backup name.\n\n`--no-sync` is used to prevent syncronisation with google drive, useful for testing because it can be slow.\n\nThe created backup files paths will be like:\n```bash\n~/grive/dev_backups/RaNdOm16DIgSrInG/\n~/grive/dev_backups/RaNdOm16DIgSrInG/RaNdOm16DIgSrInG.tar.gz\n~/grive/dev_backups/RaNdOm16DIgSrInG/RaNdOm16DIgSrInG.sql\n```\n\n### Backup-delete.sh\nRemoves backups older than a certain date (optionally syncs files with google drive)\n\n##### Options:\n    \n    -h, --help            show brief help\n    -b, --backups-path    path to backups dir (required)\n    -k, --keep            keep backups this time onwards (e.g. \"1 hour\", \"1 days\") (required). See 'man date' for more formatting options. (required)\n    --dry-run             show matching files, no deletion\n    --no-sync             bypass sync with google drive\n    \n##### Example:\n\n```bash\n$ ~/wp-backups/backup-delete.sh --backups-path \"~/grive/dev_backups\" --keep \"30 days\" --dry-run --no-sync\n```\n\nIt finds directories in `~/grive/dev_backups` older than than `30 days` counted from the script's execution time. As `--dry-run` flag is used, It just lists them, otherwise It would delete them.\n\n`--no-sync` is used to prevent syncronisation with google drive, useful for testing because it can be slow.\n\n### Backup-restore.sh\nRestores backup by name\n\n##### Options:\n\n    -h, --help                show brief help\n    -n, --backup-name         considered as the dir name that contains the backup files (required)\n    -b, --backups-path        path to backups dir (required)\n    -d, --document-root-path  path to app files (required)\n    --db-name                 app db name (required)\n\n##### Example:\n```bash\n$ ~/wp-backups/backup-restore.sh --backup-name \"RaNdOm16DIgSrInG\" --backups-path \"~/grive/dev_backups\" --document-root-path \"/var/www/html\" --db-name \"test-db\"\n```\n\nIt emptys the directory `/var/www/html` and extracts the .tar.gz files from the `RaNdOm16DIgSrInG` backup to it. Emptys the database `test-db` and import the database from the `RaNdOm16DIgSrInG` backup to it.\n\n### Logging\n\nEach script outputs (stdout, stderr) to the console and to a .log file in real time. The log paths are:\n```\n~/grive/dev_backups/backup.log\n~/grive/dev_backups/backup-delete.log\n~/grive/dev_backups/backup-restore.log\n```\n\nThe recommended way to list your `~/grive/dev_backups` directory:\n\n```bash\n$ ls -lart --time-style=+\"%Y-%m-%d %H:%M:%S\" ~/grive/dev_backups\n```\nThat way they'll be displayed in a similar format to that of the log files.\n\n## Tutorial\n\n### Installing WP CLI\nPlease refer to http://wp-cli.org/#installing\n\n### Install WP Maintenance Mode plugin\n```bash\n$ wp plugin install WP-Maintenance-Mode --path=/var/www/html\n```\n\n### Installing and setting up grive2\n\nInstall as per the [offical repo](https://github.com/vitalif/grive2), [or](http://www.webupd8.org/2015/05/grive2-grive-fork-with-google-drive.html):\n```bash\n$ sudo add-apt-repository ppa:nilarimogard/webupd8\n$ sudo apt-get update\n$ sudo apt-get install grive\n```\nSetup grive2 to sync the `grive` folder:\n```bash\n$ mkdir ~/grive\n$ cd ~/grive\n$ grive -a\n```\nIt'll request you an auth code, and then It'll read the remote files. When it finally start synchronizing files\n(the whole google drive contents) we can cancel operation with `ctrl+c`.\n\nThe reason, It's simplier to use grive2 to exclusively sync a subfolder `~/grive/dev_backups` that contains our backups, than syncing the whole google drive contents.\n\nCreate the subfolder:\n```bash\n$ mkdir ~/grive/dev_backups\n```\n\nNow, at any point we want to sync our backups directory, We can:\n```bash\n$ grive -V -P -p ~/grive -s dev_backups\n```\nThat's what WP Backups does.\n\n### Installing WP Backups\n\nGet WP Backups to your system:\n```bash\n$ wget https://github.com/decimoseptimo/wp-backups/archive/master.tar.gz -P ~\n$ tar -xvzf ~/master.tar.gz\n$ mv ~/wp-backups-master ~/wp-backups\n$ chmod 764 ~/wp-backups/*\n```\n\nSetup your mysql/mariadb crendentials by creating a `~/.my.conf` file:\n```bash\n[client]\nuser=YOUR_MYSQL_USER\npassword=YOUR_MYSQL_PASSWORD\n```\n\n(Optional)\nWe can set some values that are frequently used, as environmental variables.\nAppend this to your `~/.bashrc` file:\n```\n# wp-backups vars\nexport DOCUMENT_ROOT_PATH=\"/var/www/html\"\nexport BACKUPS_PATH=\"/home/ubuntu/grive/dev_backups\"\nexport DB_NAME=\"test-db\"\n```\n\nFor our environmental variables to work in in Ubuntu Server 16.04, we had to comment out a line in `~/.bashrc`:\n```bash\n# If not running interactively, don't do anything\ncase $- in\n    *i*) ;;\n#      *) return;;\nesac\n\n```\n\nThen we source the .bashrc file:\n````bash\n$ . ~/.bashrc\n````\n(/Optional)\n\nEdit your crontab file:\n```bash\n$ crontab -e\n```\n\nIn this example we're going to create backups every 5 minutes. And just 1 minute before that, delete backups older than than 30 minutes. Add this to your crontab file:\n\n```bash\nSHELL=/bin/bash\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n\n4-59/5 * * * * . $HOME/.profile; ~/wp-backups/backup-delete.sh --keep \"30 minutes\" --no-sync\n*/5 * * * * . $HOME/.profile; ~/wp-backups/backup.sh -m \"Cron backup\" --no-sync\n``` \n\nAs you can see we're calling the scripts omitting some required flags, specifically those already setup as enviromental variables. Otherwise we'd have to send `--backups-path --document-root-path --db-name` as appropiate.\n\nThe SHELL and PATH lines are required so that the script runs in bash, and the paths are available to it.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecimoseptimo%2Fwp-backups","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdecimoseptimo%2Fwp-backups","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecimoseptimo%2Fwp-backups/lists"}