Backup the easy way with a DOS script

I never had success with Safepoint. I was able to follow the instructions by nicktee55 and use rsync but the speed was slow. Being more comfortable in DOS than linux I decided to go with a batch file to handle my backups. I have a decent PC running windows 10 as a Plex server that is on all the time so letting it do backups is simple.

This is what I did:
1 created a new folder - C:\BackupFiles
2 created a new text file called backup.txt
3 opened backup.txt and entered this text: (no carriage return in the robocopy lines -wordwrap)

@echo off
rem robocopy [source] [destination] /[switches]
rem /copy:dt copies dates and timestamps of originals
rem /fft needed because ext3 and ntfs timestamps are different
rem /e includes all directories including empty ones
rem replace /e with /mir to make destination an exact copy *** will delete files on destination ***
rem /np no progress percents in log file
rem /log+:[filename] appends backup info to log file
rem /r:[n] number of retries per file - default is 1,000,000
rem /w:[n] time to wait between retries
rem you need /r because the job will never finish if you hit an error with 1,000,000 retries
rem
@echo on
robocopy \\MCMname\share1name \\DestDeviceName\share1BUname /copy:dt /e /fft /np /r:3 /w:30 /log+:c:\BackupFiles\backuplog.txt
robocopy \\MCMname\share2name \\DestDeviceName\share1BUname /copy:dt /e /fft /np /r:3 /w:30 /log+:c:\BackupFiles\backuplog.txt

4 saved the text file
5 renamed the text file backup.bat (you need to have Windows display filename extensions to do this)
6 used Windows Task Scheduler to run the backup.bat file everyday at 2:01 am
(Don’t want it running twice on a DST change day)
7 had an ice cold vodka gimlet - hold the lime and syrup

This runs great and the speed is about 10x faster than I was getting using rsync. The backuplog.txt file gets appended each time it runs. You can get a replacement log file each day by removing the β€˜+’ in the /log switch.

I made a separate file that I can run with the /mir switch that will clean up any deletes I made in the source. Be careful with the /mir switch because anything not in the source will be deleted from the destination. You may not need the /copy:dt or /fft switches depending on your drives. I had to add them because one of my destination drives is a USB drive formatted as NTFS.

As with anything test this out thoroughly with a small directory and see how file changes are handled. You can also use this to back up to your MCM by putting it in the destination of the robocopy command. If you have spaces in the folder names of your source or destination you will need quotes around the source and/or destination.

This worked perfectly for me because my PC is on 24/7, YMMV.

2 Likes

Thank you very much for sharing. This is actually quite helpful, and options are always welcomed.

The log file above would just get appended each time and you would have to scroll to the end to check what happened. I decided to have it create a new log file each time using the system date & time. Replace the contents of step 3 with:

@echo off
rem robocopy [source] [destination] /[switches]
rem /copy:dt copies dates and timestamps of originals
rem /fft needed because ext3 and ntfs timestamps are different
rem /e includes all directories including empty ones
rem replace /e with /mir to make destination an exact copy *** will delete files on destination ***
rem /np no progress percents in log file
rem /log+:[filename] appends backup info to log file
rem /r:[n] number of retries per file - default is 1,000,000
rem /w:[n] time to wait between retries
rem you need /r because the job will never finish if you hit an error with 1,000,000 retries
rem
rem create filename
set d1=%date:~-4,4%
set d2=%date:~-10,2%
set d3=%date:~-7,2%
set t1=%time:~0,2%
::if β€œ%t1:~0,1%” equ " " set t1=0%t1:~1,1%
set t1=%t1: =0%
set t2=%time:~3,2%
set t3=%time:~6,2%
set logname=c:\BackupFiles\backuplog_%d1%-%d2%-%d3%_%t1%-%t2%-%t3%%.txt
@echo on
robocopy \\MCMname\share1 \\DestName\share1bu /copy:dt /fft /e /np /r:3 /w:30 /log:%logname%
robocopy \\MCMname\share2 \\DestName\share2bu /copy:dt /e /fft /np /r:3 /w:30 /log+:%logname%