-
Notifications
You must be signed in to change notification settings - Fork 0
/
folder-backup-and-recover.bat
146 lines (120 loc) · 3.87 KB
/
folder-backup-and-recover.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
@echo off
setlocal enabledelayedexpansion
echo ******************************
echo Backup Folder and Recover
echo Written by Patrick Mayer 2019
echo ******************************
set folderDate=%date:~-4%-%date:~-7,2%-%date:~-10,2%
set backupLocationBase=P:\folder-backup-and-recover\%folderDate%
goto getType
:: Select Type of Job
:getType
set /p type="(o)utlook signature, (f)avorites, (e)xcel macros or (all) for everything:"
if "%type%" == "o" (
set backupTarget=C:\Users\%username%\AppData\Roaming\Microsoft\Signatures
set backupLocation=%backupLocationBase%\outlook
)
if "%type%" == "f" (
set backupTarget=C:\Users\%username%\Favorites
set backupLocation=%backupLocationBase%\favorites
)
if "%type%" == "e" (
set backupTarget=C:\Users\%username%\AppData\Roaming\Microsoft\Excel\XLSTART
set backupLocation=%backupLocationBase%\office\XLSTART
)
if "%type%" == "all" (
set len=6
set backup[0].Target=C:\Users\%username%\AppData\Roaming\Microsoft\Signatures
set backup[0].Location=%backupLocationBase%\outlook
set backup[1].Target=C:\Users\%username%\Favorites
set backup[1].Location=%backupLocationBase%\favorites
set backup[2].Target=C:\Users\%username%\AppData\Roaming\Microsoft\Excel\XLSTART
set backup[2].Location=%backupLocationBase%\office\XLSTART
set backup[3].Target=C:\Users\%username%\Desktop
set backup[3].Location=%backupLocationBase%\desktop
set backup[4].Target=C:\Users\%username%\Documents
set backup[4].Location=%backupLocationBase%\documents
set backup[5].Target=C:\Users\%username%\Pictures
set backup[5].Location=%backupLocationBase%\pictures
set i=0
goto looperman
)
if "%type%" == "q" ( goto EOF )
if "%type%" == "exit" ( goto EOF ) else ( goto wrong_input )
goto getAction
:: Select if backup or recovery
:getAction
set /p action="(b)ackup or (r)ecover - (q)uit:"
if "%action%" == "b" ( goto backup_job )
if "%action%" == "r" ( goto recover_job )
if "%action%" == "q" ( goto EOF )
if "%action%" == "exit" ( goto EOF ) else ( goto wrong_input )
:: Backup Job
:backup_job
if exist %backupLocation% (
echo %backupLocation% already exists.
) else (
echo %backupLocation% not existent. Creating now..
mkdir %backupLocation%
)
echo BackupTarget "%backupTarget%\*"
xcopy "%backupTarget%\*" "%backupLocation%\" /SY
echo Backup done.
goto EOF
:: Recover Job
:recover_job
xcopy "%backupLocation%\" "%backupTarget%\" /SY
echo Recover done.
goto EOF
:looperman
set /p loop_action="(b)ackup or (r)ecover - (q)uit:"
if "%loop_action%" == "b" (
goto looperman_b
)
if "%loop_action%" == "r" (
goto looperman_r
)
if "%loop_action%" == "q" ( goto EOF )
if "%loop_action%" == "exit" ( goto EOF ) else ( goto wrong_input )
:looperman_b
if %i% equ %len% goto :EOF
set cur.Target=""
set cur.Location=""
for /f "usebackq delims==. tokens=1-3" %%j in (`set backup[%i%]`) do (
set cur.%%k=%%l
)
echo =================================================================
if exist %cur.Location% (
echo %cur.Location% already exists.
) else (
echo %cur.Location% not existent. Creating now..
mkdir %cur.Location%
)
echo BackupTarget "%cur.Target%\*"
xcopy "%cur.Target%\*" "%cur.Location%\" /SY
echo Backup done.
echo =================================================================
set /a i = %i%+1
goto looperman_b
:looperman_r
if %i% equ %len% goto :EOF
set cur.Target=""
set cur.Location=""
for /f "usebackq delims==. tokens=1-3" %%j in (`set backup[%i%]`) do (
set cur.%%k=%%l
)
echo =================================================================
echo RestoreLocation "%cur.Location%\*"
xcopy "%cur.Location%\*" "%cur.Target%\" /SY
echo Backup done.
echo =================================================================
set /a i = %i%+1
goto looperman_r
:: Chatch all other Inputs.
:wrong_input
echo Unrecognized input. Please check for a valid input.
goto getAction
:EOF
echo --EOF--
ping 127.0.0.1 -n 3 > nul
exit