Skip to content

Instantly share code, notes, and snippets.

@adawalli
Last active January 8, 2023 18:52
Show Gist options
  • Save adawalli/b1896164a5a72b14f0eec77d713ae7c0 to your computer and use it in GitHub Desktop.
Save adawalli/b1896164a5a72b14f0eec77d713ae7c0 to your computer and use it in GitHub Desktop.
Back up your Klipper Config to Google Drive

Klipper Backups to Google Drive

Have you spent a lot of time configuring your Voron? Perfect current settings? Got those klippy location coordinates exactly where you want them? How about all those fancy macros that you built and collected over the last X days. Wouldn't it SUCK to lose them due to data corruption on your SD card? The sad truth is that your sd card has a limited number of read/write cycles and will, over time, eventually fail.

If you aren't running periodic backups, you are playing a risky game. So enough fear-mongering...besides popping your card out and backing up every once in a while or rsync'ing files when it occurs to you - you should be backing those files up. There are a million ways to do this, but we are going to focus on just one here - because it's easy for most people. We are going to be running a nightly backup task to send your files to google drive. If you have a different provider in mind, you can swap the google drive settings for any of the other numerous options supported by the tool of choice for this walkthrough: rclone.

Prerequisites for this walkthrough

  • You have an active google account
  • You know how to SSH into your raspberry pi running klipper (this would actually work for any raspberry pi based setup, but I am just going with the popular option)
  • You have an active internet connection from the pi and a route to the interwebs

Let's roll First off, I am not going to rewrite documentation that is better explained on rclones website, so please keep that in mind!

  • First off, we are going to use the official rclone installation script. you should always read a script that you are about to execute...especially when passing to sudo. You have been warned!
curl https://rclone.org/install.sh | sudo bash
  • If this went well, you should have the rclone on path. You can check that it's working with rclone --version FWIW, I am on v1.57.0
  • type in rclone config
  • At this point, I want to let you know that everything below (and more) can be found on rclone's page about google drive: https://rclone.org/drive/
  • Type N for a new remote
  • Name your remote...I use gdrive
  • We are now to select google drive as the backend storage - Depending on your terminal, it might be impossible/hard without some unix skills to read the full list to identify Google Drive on the "Type of Storage" selection. As of this writing, it is option 16
  • When asked for your oauth secret or client_id, it's ok to leave these blank (just hit enter to move on). There are ways to make your own ID and this will speed up transfers, but we are not going to get too complicated for this writeup
  • When asked about permissions, I also follow least-privilege. This would be option 3, which allows ONLY FILES created by rclone to be visible.
  • When asked about ID of the root folder...If you are like me, you don't want these dumped in the root of your google drive. Go into google drive real quick and make a folder...call it klipper_backups. Click into this folder and copy the portion in your URL that comes after folders. e.g., https://drive.google.com/drive/u/0/folders/XXXXXXXXXXXXXXXXXXXXXXX_Y - you are looking for the XXXXXXXXXXXXXXXXXXXXXXX_Y portion in my example. Paste this into the "root_folder_id" field
  • Leave Service Account Blank
  • When asked about advanced config, you can just hit enter (No will be selected by default)
  • When Asked about auto config - You must select no!!
  • You will be given an HTTPS url (it's pretty long). Copy this into your regular computer browser. We are authorizing rclone to google drive now (according to the permissions you selected above).
  • If you approve the request, google will now tell you to copy the code it gives you to your application. Go ahead and copy that whole weird code (or hit the picture of the clipboards to do it for you)
  • Switch back over to your terminal and paste this into the terminal and hit enter(the terminal should say config_verification_code). (most terminals allow you to right click for paste. In putty, this will actually paste right away. In linux/mac terminals, you will see a dropdown for paste)
  • Select No when asked about team drive
  • You will see a review page...you can hit Y for yes

OK, you are past the difficult part. Assuming you did each step now, we are ready to test and see if basic usage is working.

  • in your terminal session type in the following commands
$ cd /tmp
$ echo "This is a test!" > samplefile.txt
$ rclone copy samplefile.txt gdrive:
  • Open up your klipper_backups folder in google drive, and you should see samplefile.txt! Feel free to delete this now
  • Now let's try to backup your real files!
  • the following command assumes your config is located at /home/pi/klipper_config - please substitute this if you have your config in a non-standard location
  • rclone --verbose copy /home/pi/klipper_config/ gdrive:
  • You should now have your first backup of your klipper config located on google drive!
  • It's now time to make this a nightly task, automated by linux. We will use cronjob.
  • from your shell, execute EDITOR=nano crontab -e
  • Use your arrow keys to get to the very bottom of the file and paste in the following command 0 22 * * * /usr/bin/rclone copy /home/pi/klipper_config/ gdrive: > /dev/null 2>&1
  • This tells crontab to run this command every single day at 22:00 (in whatever timezone your pi is configured)
  • Exit Nano, by typing in Ctrl-X, Type in Y to say yes to saving buffer
  • Press Enter one last time

You are finished. You should have a nightly backup of your config now!

@spikeygg
Copy link

This works awesome! Thanks @adawalli!! I've got mine configured.

@UrufuShinjiro
Copy link

UrufuShinjiro commented May 12, 2022

On the step "You will be given an HTTPS url (it's pretty long)" I'm not getting a URL, I'm getting a linux command to run on a linux machine with a browser and it's asking for a config_token from running that command. I do not have a linux machine with a browser.

EDIT: I was able to past the command into Windows CMD after downloading rclone for windows and running the command from the correct folder

@jwhite505
Copy link

Using version 1.59.1 there were two differences, first, in order to get to the prompt for the URL code, you have to answer Yes to "Edit advanced config?". I just hit enter on the other advanced settings to choose the defaults. The other was difference was pointed out already, but no HTTPS URL was presented, instead I had to perform the token operation on my Windows PC using rclone there, but that worked simply enough.

Everything else worked great, and I appreciate you taking the time to put together the instructions.

@adawalli
Copy link
Author

Thank you both for feedback - I will go through this flow again soon and update the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment