# Backing up to Google Drive with Rclone on Ubuntu

## 1. Install Rclone

- Open a terminal on your Ubuntu machine.
- Run the following command to install Rclone:

  ```
  sudo apt install rclone
  ```

## 2. Configure Rclone

- In the terminal, run the following command to start the Rclone configuration:

  ```
  rclone config
  ```

- Choose "n" for a new remote and press Enter.
- Enter a name for your remote (e.g., "gdrive") and press Enter.
- Select "drive" as the storage type for Google Drive and press Enter.
- Press Enter to use the default client ID and client secret.
- Leave the scope as default and press Enter.
- Select "1" for "Full access to all files" and press Enter.
- Leave the "root_folder_id" and "service_account_file" empty by pressing Enter.
- Select "n" for no advanced config and press Enter.
- Choose "n" for no auto config and press Enter.
- A URL will be provided. Open it in a web browser, log in to your Google account, and grant permissions to Rclone.
- Copy the authorization code, paste it into the terminal, and press Enter.
- Choose "n" for no team drive and press Enter.
- Verify that the configuration looks correct and choose "y" to save it.

## 3. Create a backup script

- Open a text editor (e.g., nano) to create a backup script:

  ```
  nano /var/www/backup.sh
  ```

- Copy and paste the following content into the script (MAKE SURE TO CHANGE LABNAME):

  ```bash
  #!/bin/bash
  
  source_dir="/var/www/vlsm"
  remote_name="gdrive"
  remote_dir="LABNAME"
  
  rclone sync "$source_dir" "$remote_name:$remote_dir"
  ```

- Modify the `source_dir`, `remote_name`, and `remote_dir` variables according to your setup.
- Save the script and exit the text editor (Ctrl+X, then Y, then Enter in nano).

## 4. Make the script executable

- Run the following command to make the script executable:

  ```
  chmod +x /var/www/backup.sh
  ```

## 5. Run the backup script

- Execute the backup script by running:

  ```
  /var/www/backup.sh
  ```

- Rclone will start syncing the `/var/www/vlsm` folder to your Google Drive.

## 6. Automate backups

- Run the following commands to automate the backups:

```
(crontab -l 2>/dev/null | grep -q "@reboot /var/www/backup.sh" || echo "@reboot /var/www/backup.sh") | crontab -
```

```
(crontab -l 2>/dev/null | grep -q "0 */6 * * * /var/www/backup.sh" || echo "0 */6 * * * /var/www/backup.sh") | crontab -
  ```

That's it! You have now set up Rclone on your Ubuntu machine and created a script to backup the `/var/www/vlsm` folder to Google Drive. The backup will run automatically based on the schedule you specified in the cron job.