Laptop Backup and Other Batch Commands

Below are my experiences on laptop configuration to ensure least data loss in case of accident. For compression I have use open source 7zip (www.7-zip.org) and for file operations I use Windows command line interface.

Partitions

Separate partitions for Operating system and program files, SQL databases/log, Swap file, and documents. Once folder is created on documents partitions it can be added to My Documents and used by default instead of the one residing on C drive.

Backup

I found in the past that 2 types of file backup are required: (a) replace target file with compressed version of itself (b) create copy of all files/subfolders of a given folder in different location. The first is useful for large files that are rarely accessed (various uncompressed backup and database files). 

Example
FOR /R "F:\SQLBackup\Gemini" %%A IN (*.bak) DO ( "C:\Program Files\7-Zip\7z.exe" a -t7z -pYour-Password-Here "%%A.7z" "%%A" )
DEL /S "F:\SQLBackup\Gemini\*.bak"

The second is used in instances of frequently changed data, where we want to have various versions of file/folder saved at set intervals.

Example
SET stamp=%date:~6,4%%date:~3,2%%date:~0,2%
"C:\Program Files\7-Zip\7z.exe" a -pYour-Password-Here E:\backup\docs\my_doc_%stamp%.7z d:\users\alex\documents

Copy

Next step is copying the backup files to network location. For this I use ROBOCOPY, see help for list of all parameters. Example below shows how to copy all files up to 2 days old from your local drive E to a network share on machine called NETBACKUP:
ROBOCOPY E:\backup\docs \\NETBACKUP\alex\docs *.* /s /maxage:2

Delete

Last step is clean up, after the files have been compressed and copied to a network location we want to delete them from our local drive.
Example below show how to delete files over 35 days old from drive E, folder Backup:
FORFILES /p E:\Backup\docs /m *.* /c "cmd /c del @file" /s /d -35
Example below shows how to delete files less than 1GB (useful if you want to keep SQL database backups and get rid of differential and transaction log):
FORFILES /p E:\Backup\Sql /m *.* /c "cmd /c if @fsize LSS 1073741824 (del @file)" /s /d -90

All of the above can be written in Windows batch files and executed by Windows Scheduler on set intervals making whole backup process automatic. This is not a replacement of Windows backup.