Backup data to OneDrvie by rclone

Install rclone:

curl https://rclone.org/install.sh | sudo bash

Configure rclone: Once rclone is installed, you need to configure it to connect to your OneDrive account. Run the following command in your terminal:
rclone config

    rclone config

    Follow the prompts to set up a new remote. Choose “Microsoft OneDrive” as the type of storage you want to configure. You’ll need to provide your OneDrive credentials and follow the steps to authorize rclone to access your OneDrive account.

    Configure rclone Manually:

    To manually write an rclone configuration file, you can create a text file and define the configuration options. Here’s how you can do it:

    1. Create a new configuration file: Open your text editor and create a new file. You can name it anything you want, but it’s common to name it rclone.conf or something similar.
    2. Define remotes: Each remote storage provider you want to configure will have its own section in the configuration file. For example, if you’re configuring OneDrive, the section might look like this:[onedrive] type = onedrive client_id = YourClientId client_secret = YourClientSecret token = {"access_token":"YourAccessToken","token_type":"Bearer","refresh_token":"YourRefreshToken","expiry":"0001-01-01T00:00:00Z"}
      Replace YourClientId, YourClientSecret, YourAccessToken, and YourRefreshToken with your actual credentials and tokens obtained during the configuration process.
    3. Set up other options: Depending on your requirements, you may need to configure additional options such as encryption, caching, or other advanced settings. You can include these options within the respective remote section or in a global configuration section.
    4. Save the configuration file: Save the file with the appropriate name, such as rclone.conf.
    5. Place the configuration file in the correct location: By default, rclone looks for the configuration file in ~/.config/rclone/. You can either place the file there or specify its location using the --config flag when running rclone commands.
    6. Test the configuration: Once you’ve created the configuration file, you can test it by running an rclone command with the remote you’ve configured, such as:
      rclone ls onedrive
      This command should list the contents of your OneDrive if the configuration is correct.

    Create a Backup Script: Once rclone is configured, you can create a simple script to backup your files to OneDrive. Open a text editor and create a new file, e.g., backup.sh.

    #!/bin/bash
    
    # Path to the folder you want to backup
    SOURCE_PATH="/path/to/source/folder"
    
    # Remote name configured in rclone (e.g., "onedrive")
    REMOTE_NAME="remote"
    
    # Destination folder in OneDrive
    DESTINATION_FOLDER="BackupFolder"
    
    # Run rclone sync command to perform the backup
    rclone sync $SOURCE_PATH $REMOTE_NAME:$DESTINATION_FOLDER

    Replace /path/to/source/folder with the path of the folder you want to backup, remote with the name of the remote you configured in rclone, and BackupFolder with the destination folder in your OneDrive.

    # Make the Script Executable: 
    chmod +x backup.sh
    # Run the Backup:
    ./backup.sh

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *