DEV Community

Cover image for How To Backup Your VS Code Extensions And Settings
Dominik Zarsky
Dominik Zarsky

Posted on • Originally published at blog.dzarsky.eu

How To Backup Your VS Code Extensions And Settings

Backup your Visual Studio Code extension list and configuration files using Linux terminal.

Having the same working environment across multiple machines is always a good thing. This might be a case for your system configuration files (dotfiles) and your development tools alike. What I'm going to show you is a simple script that can help with the task of backing up your Visual Studio Code settings and extensions for use on your secondary PC, virtual environment or even your computer at work.

Setting up the backup

For this article, I'm going to suppose that you have VS Code already installed on your system and want to backup the settings and extensions you've spent some of your precious time setting up. We'll be using the old trusty Linux terminal magic and VS Code's command line utility code.

Our basic command for exporting the list of extensions is going to look like this:

code --list-extensions | xargs -L 1 echo code --install-extension
Enter fullscreen mode Exit fullscreen mode

The code --list-extensions command exports the list of installed VS Code extensions which we then pipe into xargs, this transforms each extension's name into an extension install command. The output of this command looks like this:

code --install-extension anseki.vscode-color
code --install-extension autsenc.laravel-blade-spacer
code --install-extension Dart-Code.flutter
Enter fullscreen mode Exit fullscreen mode

As you see we've successfully transformed the extension names to installation commands via xargs. You can output these into a file like this:

mkdir /home/$USER/code-backup && cd /home/$USER/code-backup
code --list-extensions | xargs -L 1 echo code --install-extension > ext
Enter fullscreen mode Exit fullscreen mode

Now we also need to export the configuration files. These usually reside in your .config directory. The config files are saved in JSON format, so to back these up, you would simply tar them and save them somewhere in the cloud. Alternatively, you could push these into a Git repo.

cd /home/$USER/.config/Code/User
tar -czf code-config.tar.gz *.json
mv code-config.tar.gz /home/$USER/code-backup
Enter fullscreen mode Exit fullscreen mode

In your code-backup folder, you should have your config files in a tar archive and your extension install script as ext. If you want to restore these on another machine, you'd just copy the code-backup directory's contents over and reverse the process shown above (that is, untar the config files into VS Code config directory and run the ext script)

Wrapping up

This was just a basic example of backing up your files. If you don't fancy writing backup scripts, you can check out my own full and a little enhanced implementation of this backup workflow over here. There is also a VS Code extension for synchronizing your settings called Settings Sync that synchronizes everything for you into a GitHub Gist.

Top comments (3)

Collapse
 
tygertechforce profile image
Ky • Edited

FYI: cfg_folder="/home/$USER/.config/Code/User/" does not exist for me

Excellent article and tutorial. In an effort to be helpful, I added the following "Issue" to your GitHub page regarding your "vscode-backup.sh" file that you shared:

I am not sure if VS Code is supposed to use the path you provided (cfg_folder="/home/$USER/.config/Code/User/") for storing User settings, but mine is not (that path does not exist).

I instead found my "settings.json" here:
"/Users/$USER/Library/Application Support/Code"

I then edited the "cfg_folder=..." line to match my above location.

My machine specs, in case that makes a difference or explains something:

Type: MacBook Pro 4,1 (17-inch, Early 2008; (MB166LL/A))
Processor: 2.6 GHz Intel Core 2 Duo
Memory: 4 GB 667 MHz DDR2 SDRAM
OS: OS X El Capitan (v. 10.11.6 (15G22010))
Enter fullscreen mode Exit fullscreen mode

ALSO, if you care (and are a bit anal like I am), your second line in the intro text (line 5) has a spelling error:

Script prints all intalled VSC extensions --> should be "installed"

Thanks for any comments or feedback you wish to share.

Collapse
 
dagolinuxoid profile image
Artur Haurylkevich

code --list-extensions | xargs -L 1 echo code --install-extension
It's a good one. But compressing the json file seems like overhead to me :)

Collapse
 
souris profile image
Souris

Thank you, now hopping OS is a bit more quicker :)