> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cystack.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Sao lưu dữ liệu

> Hướng dẫn thiết lập kho lưu trữ và sao lưu dữ liệu

<Card>
  **Trường hợp sử dụng**

  * Trường hợp laptop bị hỏng ổ cứng hoặc bị đánh cắp, có bản sao dữ liệu mới nhất để phục hồi, giúp nhân viên quay lại làm việc nhanh chóng.
  * Thiết bị bị mã hóa dữ liệu hoặc file bị xóa hàng loạt bởi mã độc, dữ liệu sạch có thể được khôi phục từ bản sao lưu trước đó, hạn chế thất thoát cho doanh nghiệp.
  * Công ty cấp mới hoặc nhân viên đổi sang thiết bị làm việc khác, các dữ liệu quan trọng đã sao lưu có thể được chuyển sang nhanh chóng và dễ dàng từ bản sao lưu.
</Card>

Để sao lưu dữ liệu của doanh nghiệp, người dùng cần thiết lập kho lưu trữ. Các kho lưu trữ khả dụng gồm có AWS S3, Google Drive (sắp ra mắt).

Thực hiện theo hướng dẫn dưới đây để thiết lập kho lưu trữ, và bắt đầu sao lưu dữ liệu.

***

## Sao lưu với kho lưu trữ AWS S3

### Hướng dẫn cấu hình AWS cho CyStack Endpoint

* Chuẩn bị trước account có quyền với các service IAM, S3. Sau đó tạo security key, sử dụng lệnh sau để cấu hình thông tin xác thực cho AWS CLI, giúp CLI có thể tương tác với các service AWS:

  ```bash theme={null}
  aws configure
  ```

* Thay thế các biến như `[USER_NAME]`, `[REGION]`, `[ACCOUNT_ID]`, `[BUCKET_NAME]`, `[ROLE_NAME]`, `[POLICY_NAME]` thành giá trị của bạn.

#### 1. User

<Steps>
  <Step title="Tạo user mới:">
    ```bash theme={null}
    aws iam create-user --user-name [USER_NAME]
    ```
  </Step>

  <Step title="Tạo security key cho user:">
    ```bash theme={null}
    aws iam create-access-key --user-name [USER_NAME]
    ```
  </Step>

  <Step title={<>Lưu lại <code>AccessKeyId</code> và <code>SecretAccessKey</code> từ output:</>}>
    ```json theme={null}
    {
        "AccessKey": {
            "AccessKeyId": "AKIA...",
            "SecretAccessKey": "wJalrX...",
            ...
        }
    }
    ```
  </Step>

  <Step title="Kiểm tra thông tin user:">
    ```bash theme={null}
    aws iam get-user --user-name [USER_NAME]
    ```
  </Step>

  <Step title="Lưu lại user arn từ output:">
    ```json theme={null}
    {
        "User": {
            "Path": "/",
            "UserName": "[USER_NAME]",
            "UserId": "AIA...",
            "Arn": "arn:aws:iam::[ACCOUNT_ID]:user/[USER_NAME]",
            "CreateDate": "2025-04-22T04:30:31Z"
        }
    }
    ```
  </Step>
</Steps>

#### 2. Bucket

<Steps>
  <Step title="Tạo mới bucket:">
    ```bash theme={null}
    aws s3 mb s3://[BUCKET_NAME]
    ```
  </Step>

  <Step title="Enable versioning:">
    ```bash theme={null}
    aws s3api put-bucket-versioning --bucket [BUCKET_NAME] --versioning-configuration Status=Enabled
    ```
  </Step>

  <Step title={<>Tạo file <code>bucket-policy.json</code> với nội dung sau: ()</>}>
    <Note>giá trị AWS lấy từ <code>user ARN</code> được lưu bên trên</Note>

    ```json theme={null}
    {
        "Version": "2012-10-17",
        "Id": "Policy1745394942216",
        "Statement": [
            {
                "Sid": "Stmt1745394940328",
                "Effect": "Allow",
                "Principal": {
                    "AWS": "arn:aws:iam::[ACCOUNT_ID]:user/[USER_NAME]"
                },
                "Action": [
                    "s3:ListBucket",
                    "s3:ListBucketVersions"
                ],
                "Resource": "arn:aws:s3:::[USER_NAME]"
            }
        ]
    }
    ```
  </Step>

  <Step title="Gán policy cho bucket:">
    ```bash theme={null}
    aws s3api put-bucket-policy --bucket [BUCKET_NAME] --policy file://bucket-policy.json --region [REGION]
    ```
  </Step>
</Steps>

#### 3. Tạo các role cần thiết

<Steps>
  <Step title={<>Tạo file <code>trust-policy.json</code> để cho phép user mới có quyền "assume role":</>}>
    ```json theme={null}
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Principal": {
                    "AWS": "arn:aws:iam::[ACCOUNT_ID]:user/[USER_NAME]"
                },
                "Action": "sts:AssumeRole"
            }
        ]
    }
    ```
  </Step>

  <Step title={<>Tạo role để gọi <code>AssumeRole</code>. Role này sẽ có "IAM policy" tối thiểu, kết hợp với "session policy" để kiểm soát quyền:</>}>
    <Tabs>
      <Tab title="Windows" icon="windows">
        ```bash theme={null}
        aws iam create-role ^
            --role-name [ROLE_NAME] ^
            --assume-role-policy-document file://trust-policy.json
        ```
      </Tab>

      <Tab title="Linux & macOS">
        ```bash theme={null}
        aws iam create-role \
            --role-name [ROLE_NAME] \
            --assume-role-policy-document file://trust-policy.json
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title={<>Tạo file <code>generic-backup-policy.json</code> với "IAM policy" như sau:</>}>
    ```json theme={null}
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "s3:GetObject",
                    "s3:GetObjectAttributes",
                    "s3:GetObjectVersion",
                    "s3:PutObject",
                    "s3:ListBucket"
                ],
                "Resource": [
                    "arn:aws:s3:::[BUCKET_NAME]",
                    "arn:aws:s3:::[BUCKET_NAME]/*"
                ]
            }
        ]
    }
    ```
  </Step>

  <Step title="Tạo và gán policy:">
    <Tabs>
      <Tab title="Windows" icon="windows">
        ```bash theme={null}
        aws iam create-policy ^
            --policy-name [POLICY_NAME] ^
            --policy-document file://generic-backup-policy.json
        ```

        ```bash theme={null}
        aws iam attach-role-policy ^
            --role-name [ROLE_NAME] ^
            --policy-arn arn:aws:iam::[ACCOUNT_ID]:policy/[POLICY_NAME]
        ```
      </Tab>

      <Tab title="Linux & macOS">
        ```bash theme={null}
        aws iam create-policy \
            --policy-name [POLICY_NAME] \
            --policy-document file://generic-backup-policy.json
        ```

        ```bash theme={null}
        aws iam attach-role-policy \
            --role-name [ROLE_NAME] \
            --policy-arn arn:aws:iam::[ACCOUNT_ID]:policy/[POLICY_NAME]
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title={<>Tạo file <code>central-server-policy.json</code>:</>}>
    ```json theme={null}
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "sts:AssumeRole",
                "Resource": "arn:aws:iam::[ACCOUNT_ID]:role/[ROLE_NAME]"
            }
        ]
    }
    ```
  </Step>

  <Step title={<>Gán policy cho phép user mới gọi <code>AssumeRole</code> trên <code>[ROLE_NAME]</code>:</>}>
    <Tabs>
      <Tab title="Windows" icon="windows">
        ```bash theme={null}
        aws iam put-user-policy ^
            --user-name [USER_NAME] ^
            --policy-name STSPolicy ^
            --policy-document file://central-server-policy.json
        ```
      </Tab>

      <Tab title="Linux & macOS">
        ```bash theme={null}
        aws iam put-user-policy \
            --user-name [USER_NAME] \
            --policy-name STSPolicy \
            --policy-document file://central-server-policy.json
        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>

#### 4. Thiết lập kết nối từ CyStack Endpoint đến kho lưu trữ

<Steps>
  <Step title={<>Trên giao diện quản lý CyStack Endpoint, truy cập tab "Bảo vệ dữ liệu" {'\u2192'} "Cài đặt sao lưu".</>} />

  <Step title={<>Tại danh sách "Bộ nhớ sao lưu", chọn "Dịch vụ lưu trữ S3":</>}>
    <img src="https://mintcdn.com/cystack/BpoYqzhE-ypfXZ6o/images/endpoint/s3-config-1.png?fit=max&auto=format&n=BpoYqzhE-ypfXZ6o&q=85&s=86a4c651195497598d4fac95f5ef5fb3" alt="s3-config-1" style={{display: 'block', margin: '0 auto'}} width="1540" height="854" data-path="images/endpoint/s3-config-1.png" />
  </Step>

  <Step title={<>Tại cửa sổ bật lên xuất hiện, điền thông tin lấy được từ việc thiết lập cấu hình vào, và bấm <code>Lưu</code>:</>}>
    <img src="https://mintcdn.com/cystack/BpoYqzhE-ypfXZ6o/images/endpoint/s3-config-2.png?fit=max&auto=format&n=BpoYqzhE-ypfXZ6o&q=85&s=66741fbc246cb8059abbdfe1245669e4" alt="s3-config-2" width="898" height="584" data-path="images/endpoint/s3-config-2.png" />
  </Step>

  <Step title={<>Sau khi thiết lập kết nối thành công, chuyển sang tab danh sách "Thiết bị" {'\u2192'} Bấm vào checkbox tương ứng với thiết bị muốn sao lưu {'\u2192'} bấm nút <code>Bật sao lưu</code>:</>}>
    <img src="https://mintcdn.com/cystack/BpoYqzhE-ypfXZ6o/images/endpoint/s3-config-3.png?fit=max&auto=format&n=BpoYqzhE-ypfXZ6o&q=85&s=7d245743798dd02d4d8295d18b7fc069" alt="s3-config-3" width="1651" height="633" data-path="images/endpoint/s3-config-3.png" />
  </Step>
</Steps>

Dữ liệu thuộc ổ đĩa doanh nghiệp trên các thiết bị đã chọn sẽ được tự động sao lưu 6 tiếng một lần. Việc sao lưu áp dụng với các loại file sau:
`.doc`, `.docx`, `.odt`, `.ott`, `.pages`, `.xls`, `.xlsx`, `.csv`, `.ods`, `.numbers`, `.pdf`, `.ppt`, `.pptx`, `.odp`, `.key`

***

## Khôi phục dữ liệu

Khi thiết bị xảy ra lỗi, hoặc mất dữ liệu bởi ransomware, người dùng doanh nghiệp có thể yêu cầu Chủ sỡ hữu workspace hoặc Quản trị viên khôi phục dữ liệu trong thiết bị của mình. Khi đó, Chủ sở hữu hoặc Quản trị viên khôi phục dữ liệu theo hướng dẫn sau:

<Steps>
  <Step title={<>Bấm vào biểu tượng <code>{'\u22EE'}</code> cạnh thiết bị cần được sao lưu dữ liệu, và chọn <code>Quản lý bản sao lưu</code>:</>}>
    <img src="https://mintcdn.com/cystack/jKr1Q9ZP3qaMjii7/images/endpoint/restore-snapshots-access.png?fit=max&auto=format&n=jKr1Q9ZP3qaMjii7&q=85&s=cd005e996932ab5ae3fac605cc0d58e6" alt="restore-snapshots-access" style={{display: 'block', margin: '0 auto'}} width="492" height="308" data-path="images/endpoint/restore-snapshots-access.png" />
  </Step>

  <Step title={<>Tại hộp thoại "Quản lý bản sao", chọn nút <code>Khôi phục</code>:</>}>
    <img src="https://mintcdn.com/cystack/jKr1Q9ZP3qaMjii7/images/endpoint/restore-snapshots-manage.png?fit=max&auto=format&n=jKr1Q9ZP3qaMjii7&q=85&s=dda9abf39bf2f456dd3b177e776eada2" alt="restore-snapshots-manage" style={{display: 'block', margin: '0 auto'}} width="1209" height="636" data-path="images/endpoint/restore-snapshots-manage.png" />
  </Step>

  <Step title={<>Hệ thống sẽ yêu cầu người dùng thiết bị xác nhận yêu cầu khôi phục dữ liệu.</>} />

  <Step title={<>Trên thiết bị của mình, người dùng bấm nút <code>Xác nhận</code>:</>}>
    <img src="https://mintcdn.com/cystack/jKr1Q9ZP3qaMjii7/images/endpoint/restore-client-confirmation.png?fit=max&auto=format&n=jKr1Q9ZP3qaMjii7&q=85&s=5966cd1dff9df3a75be4d972531f4f1c" alt="restore-client-confirmation" style={{display: 'block', margin: '0 auto'}} width="885" height="496" data-path="images/endpoint/restore-client-confirmation.png" />
  </Step>

  <Step title={<>Trong một số trường hợp (trên hệ điều hành Windows), người dùng thiết bị cần nhập khóa BitLocker (đã lưu trước đó) để giải mã dữ liệu sau khi khôi phục:</>}>
    <img src="https://mintcdn.com/cystack/jKr1Q9ZP3qaMjii7/images/endpoint/restore-client-bitlocker.png?fit=max&auto=format&n=jKr1Q9ZP3qaMjii7&q=85&s=89211604ed499214741b0d2fa2fc83eb" alt="restore-client-bitlocker" style={{display: 'block', margin: '0 auto'}} width="798" height="517" data-path="images/endpoint/restore-client-bitlocker.png" />
  </Step>

  <Step title={<>Sau khi khôi phục thành công, người dùng có thể truy cập được dữ liệu trên ổ đĩa của thiết bị.</>} />
</Steps>
