
Устанавливаем Rclone:
curl https://rclone.org/install.sh | sudo bash
Создаем новый конфиг и задаем ему имя:
rclone config
No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n name> GoogleDrive
Выбираем "Google Drive":
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
1 / A stackable unification remote, which can appear to merge the contents of several remotes
\ "union"
2 / Alias for a existing remote
\ "alias"
3 / Amazon Drive
\ "amazon cloud drive"
4 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
\ "s3"
5 / Backblaze B2
\ "b2"
6 / Box
\ "box"
7 / Cache a remote
\ "cache"
8 / Dropbox
\ "dropbox"
9 / Encrypt/Decrypt a remote
\ "crypt"
10 / FTP Connection
\ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
\ "google cloud storage"
12 / Google Drive
\ "drive"
13 / Hubic
\ "hubic"
14 / JottaCloud
\ "jottacloud"
15 / Local Disk
\ "local"
16 / Mega
\ "mega"
17 / Microsoft Azure Blob Storage
\ "azureblob"
18 / Microsoft OneDrive
\ "onedrive"
19 / OpenDrive
\ "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ "swift"
21 / Pcloud
\ "pcloud"
22 / QingCloud Object Storage
\ "qingstor"
23 / SSH/SFTP Connection
\ "sftp"
24 / Webdav
\ "webdav"
25 / Yandex Disk
\ "yandex"
26 / http Connection
\ "http"
Storage> drive
"Client Id" и "Client Secret" не указываем:
Google Application Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>
Google Application Client Secret
Даем полные права:
Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
1 / Full access all files, excluding Application Data Folder.
\ "drive"
2 / Read-only access to file metadata and file contents.
\ "drive.readonly"
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
\ "drive.file"
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
\ "drive.appfolder"
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
\ "drive.metadata.readonly"
scope> 1
Следующие настройки оставляем пустыми:
Service Account Credentials JSON file path
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file>
Расширенные настройки не задаем:
Edit advanced config? (y/n) y) Yes n) No y/n> n
Выбираем "No", так как у нас нет графики:
Remote config Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machine or Y didn't work y) Yes n) No y/n> n
Пулучаем сообщение вида:
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815644.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=c376b0f0f28b32b98f50e5dde0d5c7c8 Log in and authorize rclone for access
Копируем ссылку и открываем в браузере, входим в Google аккаунт, разрешаем доступ Rclone и ответ получаем токен. Возвращаемся в консоль, и вводим токен:
Enter verification code> 4/twCL5mas7QIln8g89uF2jztXKjrey0RnWrlzJ8hv0lcjE8Pc3KKLIoc
Configure this as a team drive?
y) Yes
n) No
y/n> n
--------------------
[GoogleDrive]
type = drive
scope = drive
token = {"access_token":"ya29.Glt2BjmIYXAcb0i-HRNeR5f9mPsEe3YqKgHZGsEZCYIRGKgcfbyyqoHttC31h9eFAXMyBJNKHuSlaVefOEyngJzAdYijDx5G5TIK3rWVkg3577rrY4kWm_BuL6aU","token_type":"Bearer","refresh_token":"1/OwOeusXLWk7V2nIsF9T9e83bsTY8qmzbkS4MKJJSQln8R8q0B2_NvBfu-hN3YFmf","expiry":"2018-12-18T12:56:27.537430889+02:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
Name Type
==== ====
GoogleDrive drive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
Посмотреть все файлы на "Google Drive":
rclone ls GoogleDrive:
Посмотреть директории на "Google Drive":
rclone lsd GoogleDrive:
GoogleDrive — имя удаленного хоста rclone при создании.
WordPress Backup
Создадим директорию для бекапов:
rclone mkdir GoogleDrive:BACKUP/artem.services
Теперь создадим локально директорию для бекапов, с которой будем синхронизировать удаленную директорию на "Google Drive":
mkdir -p /BACKUP/artem.services
Создадим дириктория для скрипта:
mkdir /scripts
Теперь создадим скрипт для бекапирования базы "WordPress" и файлов сайта:
vim /scripts/backup_artem.services.sh
Со следующим содержимым:
#!/bin/bash
DATE=$(date +%d-%m-%Y)
BACKUP_PATH="/BACKUP/artem.services"
SITE_PATH="/var/www/html/artem_services"
DATABASE="artem_services"
mkdir $BACKUP_PATH/$DATE
tar -zcvf $BACKUP_PATH/$DATE/site.tar.gz --directory="$SITE_PATH/" ./
mysqldump -u root $DATABASE | gzip -c > /$BACKUP_PATH/$DATE/database.gz
find $BACKUP_PATH -type d -mtime +5 -exec rm -rv {} \;
/usr/bin/rclone sync $BACKUP_PATH/ GoogleDrive:/BACKUP/artem.services
Делаем его исполняемым:
chmod +x /scripts/backup_artem.services.sh
И добавляем его в крон раз в день в полночь:
crontab -e
0 0 * * * /scripts/backup_artem.services.sh