26.8 C
Texas

Auto Backup to Dropbox on Linux

Dropbox is obviously one of the most popular cloud storage solutions for everyone. The service has earned a good popularity due to the fact that the free available space is huge and it’s hugely usable in different platforms using the API. Linux users can also easily enjoy Dropbox service directly from their system, no need to open the browser and manage through the website.

Need automated file backup to Dropbox? It’s really simple to do on Linux systems. All you have to do is just configure an automated script.

Downloading the script

For using the service, you have to download the automated script from GitHub using Git. Make sure that your system has Git installed. Learn how to install Git.

Once you’ve installed Git, it’s time to grab those scripts. Run the following code:

- Advertisement -
git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
cd Dropbox-Uploader

Update the file permission of the scripts:

chmod +x dropbox_uploader.sh
chmod +x dropShell.sh
chmod +x testUnit.sh

Generating Dropbox API

Now, you have to grab the Dropbox API of your account. This is necessary so that the script can access your Dropbox storage. For grabbing your Dropbox API, go to this page.

 

Click on “Create app” button.

Now, you have to select the API type. Select the options according to the screenshot. Note that you can choose your own “App name”.

After you click the “Create app” button, you’ll get the token by clicking the “Generate” button.

Setting up the script

It’s time to finally set the script for automatically backing up your files to Dropbox. Run the script:

./dropbox_uploader.sh

When you run the script for the first time, it’ll ask for the access token. Enter the token and you’re good to go.

Now, run this command for creating a “backup” directory to your Dropbox storage.

./dropbox_uploader.sh mkdir Backup

Here, you can manually upload a file to the folder. Note that the Dropbox uploader script is able to upload more than just TAR.GZ files. You can upload ANY type of file using the same command. Just change the file path & file name and you’re good to go!

./dropbox_uploader.sh upload ~/<username>/location/of/file.tar.gz

Automating backup

Here comes the important part. You have to keep a backup of your file/folder on a regular basis, right? Open a terminal and run the following command:

sudo -s

It’ll enable the “root” access of your system. Run the following command now:

crontab -e

Once the “cron” file is open, enter the following code:

00 08 * * 6 tar -zcvf backup-$(date +%Y-%m-%d).tar.gz /home/<username>;/home/<username>/Dropbox-Uploader/dropbox_uploader.sh upload /home/username/backup-$(date +%Y-%m-%d).tar.gz Backups

This code will make sure that the “/home/<username>” directory will be compressed and uploaded to Dropbox at 8:06 AM every day. You can easily change the time and the file/folder and the path according to your need.

You’re all set! Reboot your system and do everything else as normal.

If you want to disable the auto backup, follow the same steps as above and delete the line from the “cron” file. Then, reboot your system and you’re good to go!

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article