Android Example Automatic backup of source files to zip after each compilation with Custom Build Action and 7zip

Here' s a batch file that will back up all your source files and zip it with 7zip with the datetime stamp on each successful compilation. Only external prerequisite is 7zip which is free.

It will serve as a simple automatic version control and backup to cloud if your source files are on Dropbox/ Gdrive / Skydrive.

  1. Copy attached batch file to your computer.
  2. Add the following line to your project

    #CustomBuildAction: 4,Drive:\PathToYourBatchFile\Auto7Zip4B4A.cmd, ..\ ..\BackupFolder\


  3. Compile your project
The batch file creates a date time stamp and can be customised for folder and files to be excluded and included to the created zip file. 7zip path has to be changed in the batch file if its different from the default windows 64 bit installation.

The Backup folder can have hard coded path or can use relative paths as shown above. It will be created automatically even if it does not exist.
If you want to create a Project folder as a sub folder to the backup folder just append the project folder name as in
..\BackupFolder\ProjectName\

If Project name is to be appended to zip file name just modify it to ..\BackupFolder\ProjectName\ProjectName
Please note that there is no trailing back slash in the above case.

Now you can have Time and date stamped backups for each of your projects without using export as zip file and automatically.

I have updated the batch file with more comments for customization.
 

Attachments

  • Auto7Zip4B4A2016-08-31.zip
    1.1 KB · Views: 439
Last edited:

sunish

Member
Licensed User
Longtime User
Erel, any option to get the name of the project/versionnumber as a veriable to pass to the custom build action ? I tried Application.label, but its not passing the value.
 

sunish

Member
Licensed User
Longtime User
There is no simple way to pass those values.
Since #ApplicationLabel and #VersionCode are already defined, it would a great idea to have a compile time expansion for custom build action.

Also there should be a possibility of using relative paths in Custom Build Action while calling file for execution.
 
Top