Backup dos batch
Posted: 30 Oct 2013 13:12
I'm looking to make a backup batch for several older machines in my house that don't have a built in backup utility. I have a drive on the network, both machines can see it and access it, and I've mapped the drive. I have a batch file that with user input can make a rolling backup (think like Apple's Time Machine) that only backups up altered or new files using the xcopy with the /d:[date] switch. My desired format is, if I can do it in these steps.
1. The initial batch file is used. it creates a log file that notes the date that it has run.
2. It also copies a new batch to the start menu's startup folder that runs when the computer starts with no user interaction.
3. The initial batch backups up all the users folder to the network drive in the format [networkdrive]:\Backup\[YYYY]\[MM]\[DD]\.
4. When it runs on bootup the startup batch then reads the day, month, and the year from the logfile created by the initial batch file, and plugs those parts into variables %backupday%, %backupmonth% %backupyear%
5. The batch runs xcopy in the follow syntax; xcopy [FILES] [networkdrive]:\Backup\%backupyear%\%backupmonth%\%backupday%\ /e /y /d:%backupmonth%/%backupday%/%backupyear%
6. The startup batch redirects the current date into the same logfile that the intitial batch created, so that the next time it runs, it will simply add the last time it was backed up into the variables and thus only backup files that have been created or changed since then.
This command should backup all files modified or created after a certain date
The only issue I am facing is finding out how to extract *just* the numerical date (ignoring the mon or fri for the day of the week) and placing it into the logfile, and how to then extract just the day or month or year out of the logfile and plug it into variables. I suspect findstr or something similar is going to be needed.
1. The initial batch file is used. it creates a log file that notes the date that it has run.
2. It also copies a new batch to the start menu's startup folder that runs when the computer starts with no user interaction.
3. The initial batch backups up all the users folder to the network drive in the format [networkdrive]:\Backup\[YYYY]\[MM]\[DD]\.
4. When it runs on bootup the startup batch then reads the day, month, and the year from the logfile created by the initial batch file, and plugs those parts into variables %backupday%, %backupmonth% %backupyear%
5. The batch runs xcopy in the follow syntax; xcopy [FILES] [networkdrive]:\Backup\%backupyear%\%backupmonth%\%backupday%\ /e /y /d:%backupmonth%/%backupday%/%backupyear%
6. The startup batch redirects the current date into the same logfile that the intitial batch created, so that the next time it runs, it will simply add the last time it was backed up into the variables and thus only backup files that have been created or changed since then.
This command should backup all files modified or created after a certain date
The only issue I am facing is finding out how to extract *just* the numerical date (ignoring the mon or fri for the day of the week) and placing it into the logfile, and how to then extract just the day or month or year out of the logfile and plug it into variables. I suspect findstr or something similar is going to be needed.