My failsafe development environment
Tags: storage, repository, webdev, nas
Published: 2024-05-05 11:19:48

## The problem

As a developer, I live in the constant fear of losing my source code or ending up with an out-of-date branch on Git Hub due to last-minute-almost-on-production changes.
Besides that, I have to handle project synchronization between my devices...
- Desktop workstation (where most of the work is done);
- Laptop workstation (to work on-premises fix);
- Local server (which is both a NAS and a dev-test server).
...and my cloud storage:
- Github;
- Dropbox;

That's how I solved my problem using:
- Dropbox;
- A BTRFS filesystem shared with NFS on my Local Ubuntu Server.

## The workflow

Typically, when working on a project, I go through two phases:

- The playground phase where code parts are tested/produced for general evaluations. Any material produced in this phase can be safely deleted afterward or doesn't need to be saved;
- The development phase where the code specific to the application is actually produced and should only be saved on Dropbox if they are modules containing partial functionalities or test environments, and on both Dropbox and GitHub if it's final application code.

## The setup

With that said, the solution I've found that works best for each device is outlined below.

### Server

Starting with the server since it's the core of the entire system.
It's a small server I assembled myself, running Ubuntu Server 22.04 LTS to use it as both a NAS and a test server for applications.
The operating system is installed on a 250GB WD SSD, and it's connected with 2 WD Red Pro 6TB HDDs specifically designed for NAS. The disk configuration is as follows:

- 250GB SSD: Contains only the operating system;
- 2x 6TB HDDs: Configured in RAID1 using BTRFS and mounted on the OS at boot to /mnt/data.

All data is contained in the BTRFS filesystem (named "data") shared over the network using NFS share (which, from my tests, seems to be the only sharing system capable of decently supporting intensive write operations).

The "data" filesystem is organized as follows:

```
cloud/
├─ Dropbox/
local/
├─ ernesto-desktop/
│  ├─ bin/
│  ├─ bkp/
├─ ernesto-laptop/
│  ├─ bin/
│  ├─ bkp/
├─ ernesto-server/
│  ├─ bin/
│  ├─ bkp/
├─ playground/
```

The local folder should contain all the data that is needed to survive a device reinstall or configuration backup.
The cloud folder is where Dropbox will perform a complete sync of the entire cloud (to have a local copy of the entire cloud in case of emergency).

> Note that I use a Dropbox business account, so I have no limits in terms of cloud space. If you're interested in how I installed Dropbox to work in a folder other than the user's home, leave me a comment, and I'll write an article about it.

### Desktop & Laptop

Once the server is configured, all that's left is to install Dropbox on both the desktop and the laptop and mount the NFS share containing our cloud backup at startup.

## Conclusion

This way, I can comfortably work on my code from the NFS share in both the playground and development phases. If I need to work on the go with my laptop, I can sync the projects I'm interested in using Dropbox and have a single control point (my dev server, which always contains the latest version of the code saved by Dropbox) to ensure that my GitHub repositories are in sync with the local ones.