Google Drive Cloud Storage for WP-CLI
MIT License
Use Google Drive Storage in WordPress WP-CLI Command line for Backup/Restore Files.
you can install this package with:
wp package install wp-packagist/wp-cli-gdrive-command
Installing this package requires WP-CLI v2 or greater. Update to the latest stable release with
wp cli update
.
Step 1: Go to Google Developers console and Create a new project
Step 2: Create an OAuth client ID
You can select Other types for the project.
Then copy your Client Id and Client secret.
Step3 : run command and enter your Client id and Client secret.
wp gdrive auth
if you want change gmail account that saved before. use 'wp gdrive auth --force'.
NAME
wp gdrive
DESCRIPTION
Google Drive Cloud Storage.
SYNOPSIS
wp gdrive <command>
SUBCOMMANDS
auth Verify user identity on Google.
copy Copy a file or folder.
get Download a file.
ls List of files and folder.
mkdir Create folder in Google Drive.
move Move a file or folder.
private Private a file or folder.
rename Rename a file or folder.
restore Restore a file and folder from trash.
rm Remove File or folder By Path.
share Get Download Link a file or folder.
storage Verify user identity on Google.
trash List of files and folder in trash.
upload Upload a file.
List of WP-CLI gdrive Commands :
For show list all files and folder in root dir :
wp gdrive ls
For show list of files from custom path e.g /wordpress/backup
wp gdrive ls /wordpress/backup
For creating a folder use :
wp gdrive mkdir <path>
create backup
folder in the root directory:
wp gdrive mkdir backup
you can also create nested dir. for example:
wp gdrive mkdir wordpress/new-project/backup
wp gdrive get <path> <save-to> [--name=new_name] [--e]
Download backup.zip file from root dir in Google Drive:
wp gdrive get backup.zip
Download backup.zip file and save to custom dir with package.zip
name:
wp gdrive get backup.zip /folder/ --name=package.zip
Automatic unzip file after download: (use --e flag) Download Backup.zip file and extract to /folder/.
wp gdrive get backup.zip /folder/ --e
wp gdrive copy <path> <new-path>
new-path
is only new dir path.
for example copy file:
wp gdrive copy /backup/wp.zip /folder/custom/
or copy folder:
wp gdrive copy /folder/name/ /custom
wp gdrive mv <path> <new-path>
or
wp gdrive move <path> <new-path>
For example:
wp gdrive move /folder/wordpress.zip /folder/custom/
wp gdrive rm <path> [--trash] [--force]
or
wp gdrive remove <path> [--trash] [--force]
Path: files or folder path e.g. /backup/wp.zip --trash: Move file to trash. --force: Force removing file and folder without question.
For example remove wordpress.zip file in root directory and move to trash:
wp gdrive rm wordpress.zip --trash
wp gdrive ren <path> <new-name>
or
wp gdrive rename <path> <new-name>
For example, rename wp.zip files that stored in backup folder to wordpress.zip:
wp gdrive ren /backup/wp.zip wordpress.zip
Rename a folder:
wp gdrive ren /folder/folder/ new_folder_name
If you want to share files or folder and get public link use:
wp gdrive share <path>
for example, get download link /backup/wp.zip file:
wp gdrive share /backup/wp.zip
after download files or folder by others, you can private again file or folder:
wp gdrive private <path>
for example, disable download link /backup/wp.zip file:
wp gdrive private /backup/wp.zip
For showing list of all files and folders in Google Drive Trash:
wp gdrive trash
wp gdrive trash --clear
Use this command:
wp gdrive restore <path>
for example, restore backup
folder from Google drive trash:
wp gdrive restore /backup/
For getting your Storage:
wp gdrive storage
or
wp gdrive about
wp gdrive upload [<path>] [<UploadTo>] [--name=<file_name>] [--zip] [--force]
path
: The path of file or folder for Upload. default is current path
UploadTo : The path dir where the file will be saved in Google Drive.
--name : New file name to save.
--zip : Create Zip file before uploading.
--force : Force upload even if it already exists.
Automatic create zip file archive file from all root directory and files and upload to GDrive:
wp gdrive upload --zip
Upload backup.zip file to root dir in Google Drive:
wp gdrive upload backup.zip
Automatic create zip archive from the /wp-content/ folder and upload to custom dir:
wp gdrive upload /wp-content/ /wordpress/backup --zip
Upload All files from /wp-content/plugins/my-plugin/docs
to wordpress/plugin
directory in Google Drive
wp gdrive upload /wp-content/plugins/my-plugin/docs/ /wordpress/plugin --zip
Number Max files in One Request is 100 files
Upload with a custom name.
wp gdrive upload backup.zip --name=wordpress.zip
Get Backup From WordPress Database and Upload to Google Drive:
wp db export backup.sql
wp gdrive upload backup.sql /backup/wordpress
We appreciate you taking the initiative to contribute to this project.
Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.
Think you’ve found a bug? We’d love for you to help us get it fixed. Before you create a new issue, you should search existing issues to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.
Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project.
Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience: