Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Backing Up CLI Projects (Windows)

By default, CLI projects contain a huge node-modules directory. This doesn't need to be included in backup copies, but its presence can make manual backups harder to create. On Windows, I create backups like this...

Within my project directory, I create a subdirectory called 'code'. This is actually the root of the project as far as CLI is concerned (eg, it's where package.json lives). Keeping the code files contained like this means that I can keep other project files (documentation, screenshots, etc) outside of the code directory, but still within the project directory.

In the project directory, I have backup.bat:

@Del Backup\code\*.* /s /q
@xcopy code Backup\code /a /s /i /exclude:Backup_Excludes.txt
@if errorlevel 1 pause

...and also Backup_Excludes.txt:

package-lock.json
yarn.lock
yarn-error.log
\build
\node_modules

Executing backup.bat copies all the files in code into Backup\code, except for the files and directories listed in Backup_Excludes.txt. It overwrites anything previously in Backup\code.

Whenever you want to keep a copy of the current backup (eg, because it represents a release version), just rename Backup\code to, eg, Backup\1.0.0. Then, backup.bat won't change those files; it will create a new Backup\code directory for subsequent changes.

I also use this before doing something risky; eg, renaming Backup\code to Backup\BeforeDangerousChange.

There's still some duplication in this process (eg, identical files can be in multiple directories within Backup), and it doesn't necessarily integrate with Windows File History, OneDrive, etc.

You can also use git, but that can be harder work.

Obviously you can tailor these files to suit your own preference.

Peter McLennan
Gondwana Software
Best Answer
1 REPLY 1

Thanks @Gondwana - that's a good idea - based on that I tried this alternative.

Above all project directories I created a backup directory.

In each project directory added a backup.bat and exclude.txt with the following contents

contents of exclude.txt

exclude.txt
node_modules
backup.bat

 

contents of backup.bat

@for %%a in (.) do set currdir=%%~na
@set /p "ver=Enter version: "
xcopy * ..\backup\%currdir%%ver%.zip /a /i /s /exclude:exclude.txt

On running the BAT file you are prompted for a version

it then creates a ZIP file named "Project directory name""Version".Zip each time it is run

It will overwrite items with the same version, so version it could have a date/time added if you want to be sure it's unique.

 

In your backup directory you will end up with all the project backup zip files by project directory name.

 

 

Author | ch, passion for improvement.

Best Answer