Aside

Backup Overleaf → Dropbox → BitBucket

I used to always write using MS Word. I actually like Word since Word2010, and have not really felt the need to move to the unusable Windows TeX editors that I have tried in the past. But since starting at the University of Luxembourg I also work on a Mac, and switching between Word on two different OS’s is quite annoying. In the meantime, Overleaf has managed to become a rather usable TeX editor, so I have been working with this for the past months and must say I have grown to rather like it.

There is however one caveat; Overleaf manages all files itself and integrating it with Dropbox is almost $100/year. I do not want to just trust Overleaf with my entire thesis, so I set out to automate backups of my work. Although Dropbox does versioning, it doesn’t show the exact changes like git allows, so I wanted to also backup to BitBucket, which allows private repositories for free unlike GitHub[1]I don’t need my entire thesis writing to be public yet.. This proved not a trivial task, so I will write here how I managed to create a workflow of automatic backups for Overleaf → Dropbox → BitBucket.

© Jorge Cham

© Jorge Cham

This page might seem a bit long, but do not worry: in the end you’re going to have a file of just three lines. It is long because I detail every step for people who don’t know anything about git yet.

Requirements

We will be using git commands in the command line in Windows [2]If you’re a Linux user, good for you (and you probably don’t need this guide). If you’re a Mac user you need to install a package to run git commands. OSX advises XCode, which is a 3.2GB package which I thought was a bit much to be able to type three letters. There are other packages that are smaller, but then you need to manually point the terminal to that package and I grew tired, so I continued on Windows.. Before we start, download and install Git for Windows.

During installation, make sure to install git for the commandline, since this is what we’ll be using. See the settings in the screenshots below.

gitbash-cmd gitbash-windows

To check whether your package works, type git into the commandline and see what happens. If it lists a number of possible actions, you can continue to the next step.

Overleaf → Dropbox

Overleaf has created a way to access your projects via git, see their tutorial. What is important now is that you open the Share menu and copy-paste the link under “Clone with git”, which starts with https://git.overleaf.com/ and then some letters and numbers.

Setup

First, we need to set up a local folder where your files will be saved. Open your file explorer and browse to a folder in your Dropbox where you want to save everything in a new folder. In my case, /dropbox/research/phd/. In this folder, right-click and create a new text document that you call backup.bat (do not forget to change the extension from .txt to .bat!).  We will be cloning Overleaf to a folder named overleaf-backup. Edit this file with notepad and fill in the following:

git clone https://git.overleaf.com/<yoururlhere> overleaf-backup

Save, and double-click the backup.bat file, it should now copy the entire repository with all the files to your hard drive, and Dropbox will start syncing the folder overleaf-backup.

Downloading updates

Second, we want to keep these files up-to-date. Edit the backup.bat file again with notepad and above the previous line, add the following to point to your new folder[3]An earlier version of this post described simply pointing to the folder, rather than the full path. I changed this because providing the full path proved more robust.:

cd "C:\Users\<yourusernamehere>\Documents\Dropbox\research\PhD\overleaf-backup"

Do note the quotes here, and provide the full path of your overleaf-backup folder, the above is an example of how it looks for me.

We cannot use the clone command because the local files already exist. Instead, we will pull, so edit the backup.bat file again with notepad and change clone to pull, and remove the folder name at the end:

git pull https://git.overleaf.com/<yoururlhere>

Now whenever you run the backup.bat file, it will download all the updates to the overleaf-backup folder.

Result

Your back.bat file should now contain the following 2 lines:

cd "C:\Users\<yourusernamehere>\Documents\Dropbox\research\PhD\overleaf-backup"

git pull https://git.overleaf.com/<yoururlhere>

Try to edit a line in your overleaf, and then run the backup.bat file by opening it. Open in dropbox the .tex file that you edited (probably full_article.tex) with Notepad to see if the change is there. Does it work? Good, next we will sync to another git repository, or if you want we can jump to “Automating this“.

Dropbox → BitBucket

We now have a local backup of our work. Although Dropbox does versioning, it does not show the differences between versions. For this, we need a proper git repository (and the added advantage of another backup). As BitBucket allows private repositories, we will be using this.

Setup

First, if you haven’t done so already, sign up for a BitBucket account. For authorization, choose https and create a password that you can remember.

Second, we will need to setup a BitBucket repository. This can be done from the command line, but the easiest method is probably through BitBucket. In your BitBucket dashboard, choose “Create repository” (in the top bar) and then “import a repository” (top right of the window). Here you can copy the Overleaf repository by filling in the https://git.overleaf.com/<yoururlhere>. You can also choose a name for this repository, let’s choose overleaf-backup, and select “this is a private repository”. BitBucket will clone from Overleaf to BitBucket. After this go to the overview page of your fresh repo and at the topright, copy and paste the url after HTTPS which looks like https://<your username>@bitbucket.org/<your username>/overleaf-backup.git

Uploading updates

Whenever we download the updated files from Overleaf to Dropbox, we immediately want to push them to BitBucket, so we will be using the backup.bat file. Edit it again with notepad, and add in the following line below the existing lines:

git push --mirror https://<your username>@bitbucket.org/<yourusername>/overleaf-backup.git

(This should be a single line, ignore the linebreak WordPress created)

This code shows we cannot just push our local files to BitBucket, because git assumes two-way sync, in this case between Overleaf and Dropbox. So instead of merely pushing the repository, we are mirroring it to another repository, that’s what the --mirror part does.

Result

Your backup.bat file should now contain the following 3 lines:

cd "C:\Users\<yourusernamehere>\Documents\Dropbox\research\PhD\overleaf-backup"

git pull https://git.overleaf.com/<yoururlhere>

git push --mirror https://<your username>@bitbucket.org/<yourusername>/overleaf-backup.git

Try to edit another line your Overleaf, and run the backup.bat file. It will download the Overleaf repo, and connect to your BitBucket repo where you will be asked to provide your password. Note that the commandline does not show you typing your password, so just type it and hit enter[4]Supposedly, you can skip the password by working with an SSH key, but I haven’t figured this part out myself. I got as far as that you should use Git Bash (which was installed with Git for Windows) and follow this tutorial by BitBucket, but I didn’t manage to automate it.. When the commandline-window closes, head to your BitBucket page and see if there are any commits.

Automating this

Since we’re using Windows, there is an easy way to now automate this. Create a Windows task following this tutorial, and choose “start a program” and point it to the backup.bat file: right-click the file, select “Properties”, and copy the entire path next to “Location”, fill this in in the task window. As a trigger, I chose “when user logs on”, but you can choose a different time-frame.

Try to edit a line in your Overleaf, and try to activate the trigger (in my case, reboot). Look up the .tex file that you edited (probably full_article.tex) in Dropbox to see if the change is there, and check your BitBucket for commits. Does it work? Good! You now have a fully functional back-up!

References   [ + ]

1. I don’t need my entire thesis writing to be public yet.
2. If you’re a Linux user, good for you (and you probably don’t need this guide). If you’re a Mac user you need to install a package to run git commands. OSX advises XCode, which is a 3.2GB package which I thought was a bit much to be able to type three letters. There are other packages that are smaller, but then you need to manually point the terminal to that package and I grew tired, so I continued on Windows.
3. An earlier version of this post described simply pointing to the folder, rather than the full path. I changed this because providing the full path proved more robust.
4. Supposedly, you can skip the password by working with an SSH key, but I haven’t figured this part out myself. I got as far as that you should use Git Bash (which was installed with Git for Windows) and follow this tutorial by BitBucket, but I didn’t manage to automate it.

11 thoughts on “Backup Overleaf → Dropbox → BitBucket

  1. Michele Battisti says:

    Great tutorial, thanks!!!! I am no expert but could easily follow. I have several projects on overleaf, did you find a way to somehow backup all of my overleaf projects at once? It seems that as it is when I add a new project I need to add it to the backup and to BitBucket

    • Thanks Michele! I’m glad you could follow the steps. Overleaf creates a separate git repository per project, so there’s no way to bulk backup them right now. What you can do however is create a single .bat file for all the backups by repeating:

      cd "C:\Users\username\Documents\Dropbox\research\PhD\overleaf-backup-1"

      git pull [overleaf-git-url-1]

      git push --mirror https://[your username]@bitbucket.org/[yourusername]/overleaf-backup-1.git

      cd "C:\Users\username\Documents\Dropbox\research\PhD\overleaf-backup-2"

      git pull [overleaf-git-url-2]

      git push --mirror https://[your username]@bitbucket.org/[yourusername]/overleaf-backup-2.git

      etc

      • Michele Battisti says:

        Thanks! Did that and it works fine. I need to enter the password for each project separately but that is okay, I do not want to try too hard to figure that our since it is not too important… Thanks again!
        have a great day,

        Michele

    • Hi osita, I’m sorry that you got stuck. If you provide in more detail where you’re stuck, I might try and help you out. You can also send me an email (see Contact) if that’s easier.

    • Hi Martin, at this point I honestly don’t really remember which ones I’ve tried, but I remember I had to install the Tex framework independently from the GUI software which was a hassle. More importantly, one requirement I had when switching to LateX again was that I should be able to switch between OSX and Windows without too much trouble, which made a browser-based authoring tool useful.

  2. Alexandre Pierrot says:

    Thank you for this tutorial Max, I can now automatically backup my Overleaf projects to my Onedrive folder which also automatically backups to an external drive. This is brilliant and a very robust solution. I’ll recommend this article to all of my university peers also using Overleaf.

Leave a Reply

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