Hướng dẫn cài đặt tự động backup định kỳ WebServer, VPS Linux lên Google Drive

Hướng dẫn cài đặt tự động backup định kỳ WebServer Linux lên Google Drive

Backup dữ liệu là công việc thường xuyên phải làm của các quản trị web (Webmaster). Việc backup dữ liệu website nhằm mục đích lưu trữ, giảm thiểu rủi ro khi hệ thống của bạn gặp các vấn đề về kỹ thuật hoặc bị tấn công. Đối với nhưng website sử dụng dịch vụ Hosting, việc backup thường nhàn hơn. Các nhà cung cấp Hosting thường có các bản backup định kỳ hàng ngày. Đối với những hệ thống sử dụng VPS hoặc ServerWeb riêng. Webmaster là người phải chủ động Backup dữ liệu.

Trong bài này, mình sẽ hướng dẫn cách đặt lên lịch backup tự động cho Webserver/VPS Linux. Sử dụng rclone để đẩy backup lên Google Drive.

RCLONE là gì?

Rclone là công cụ miễn phí giúp đồng bộ hóa dữ liệu tốc độ cao giữa máy tính được cài đặt với các dịch vụ lưu trữ đám mây.

CÁC BƯỚC THỰC HIỆN CÀI ĐẶT TỰ ĐỘNG BACKUP DỮ LIỆU WEBSERVER LÊN GOOGLE DRIVE

Cài đặt rclone lên Server Linux:

Cài đặt rclone trên hệ điều hành 64 bit:

cd /root/
wget https://downloads.rclone.org/v1.41/rclone-v1.41-linux-amd64.zip
unzip rclone-v*.zip
\cp rclone-v*-linux-amd64/rclone /usr/sbin/
rm -rf rclone-*

Cài đặt rclone trên hệ điều hành 32 bit:

cd /root/
wget https://downloads.rclone.org/v1.41/rclone-v1.41-linux-386.zip
unzip rclone-v*.zip
\cp rclone-v*-linux-386/rclone /usr/sbin/
rm -rf rclone-*

KẾT NỐI WEBSERVER/VPS VỚI GOOGLE DRIVE

Sau khi đăng nhập Webserver qua SSH, bạn gõ lệnh sau:

rclone config

Nếu bạn chưa tạo kết nối nào, sẽ nhận được thông báo sao: No remotes found – make a new one.

Để tạo mới một kết nối, bạn nhấn phím n rồi gõ Enter.

Dòng name, bạn gõ tên kết nối (viết liền không dấu, không có khoảng cách), ở đây mình nhập: BAKWEB01. Name này có thể hiểu như là tên bạn định nghĩa cho kết nối đang cài đặt. Bạn sẽ sử dụng nó mỗi khi đồng bộ dữ liệu với Cloud.

Sau khi gõ name và nhấn Enter, một danh sách các dịch vụ lưu trữ đám mây được hỗ trợ hiện ra. Để chọn đồng bộ với Google Drive bạn tìm xem Google Drive nằm trong số thứ tự bao nhiêu. Gõ số thứ tự đó và nhấn Enter. Ở phiên bản rclone 1.41, thứ tự là 11. Do đó mình gõ 11 và nhấn Enter.

Tiếp theo, dòng thông báo hỏi Client IDClient Secret hiện ra, bạn để trống và gõ Enter.

Tiếp theo là phần Scope that rclone should use when requesting access from drive, bạn nhấn 1 (Full access all files, excluding Application Data Folder). và nhấn Enter. Ý nghĩa là để cấp quyền truy cập toàn bộ files có trên Google Drive của bạn.

No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> BAKWEB01
Type of storage to configure.
Choose a number from below, or type in your own value
1 / Alias for a existing remote
\ "alias"
2 / Amazon Drive
\ "amazon cloud drive"
3 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
\ "s3"
4 / Backblaze B2
\ "b2"
5 / Box
\ "box"
6 / Cache a remote
\ "cache"
7 / Dropbox
\ "dropbox"
8 / Encrypt/Decrypt a remote
\ "crypt"
9 / FTP Connection
\ "ftp"
10 / Google Cloud Storage (this is not Google Drive)
\ "google cloud storage"
11 / Google Drive
\ "drive"
12 / Hubic
\ "hubic"
13 / Local Disk
\ "local"
14 / Mega
\ "mega"
15 / Microsoft Azure Blob Storage
\ "azureblob"
16 / Microsoft OneDrive
\ "onedrive"
17 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ "swift"
18 / Pcloud
\ "pcloud"
19 / QingCloud Object Storage
\ "qingstor"
20 / SSH/SFTP Connection
\ "sftp"
21 / Webdav
\ "webdav"
22 / Yandex Disk
\ "yandex"
23 / http Connection
\ "http"
Storage> 11
Google Application Client Id - leave blank normally.
client_id>
Google Application Client Secret - leave blank normally.
client_secret>
Scope that rclone should use when requesting access from drive.
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
ID of the root folder - leave blank normally. Fill in to access "Computers" folders. (see docs).
root_folder_id>
Service Account Credentials JSON file path - leave blank normally.
Needed only if you want use SA instead of interactive login.
service_account_file>
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=xxxx
Log in and authorize rclone for access
Enter verification code> 3/BAC5UHc4Eck-xxxx
Configure this as a team drive?
y) Yes
n) No
y/n> n
--------------------
[remote]
type = drive
client_id =
client_secret =
scope = drive
root_folder_id =
service_account_file =
token = {"access_token":"xxxx","token_type":"Bearer","refresh_token":"2/cvYxBH_72wTjsC4GExgQFdC5dgb_M2ZLnKFDwMFsViN","expiry":"2022-09-30T14:29:46.323334805-03:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:

Name Type
==== ====
remote 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

z

TẠO FILE BACKUP WEBSERVER VÀ UPLOAD TOÀN BỘ LÊN GOOGLE DRIVE

x

TÌNH HÌNH DỊCH BỆNH CORONA MỚI NHẤT

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *