[DOS] Robocopy, 压缩, 备援, GZip 备忘

Robocopy, 压缩, 备援 备忘


◆ GZip http://www.gzip.org/

   gzip myfile.dat
   gunzip myfile.dat.gz


◎ 我是我,叶子 -- 使用Robocopy时排除特定目录 2013-9-16

◎ 我是我,叶子 -- Windows 中使用 robocopy 进行文件差异备份的相关排程语法说明 2013-3-19

   1.建立存放差异文件用的目录
    md d:backup
    md d:backupwwwroot
   
   2.开始产生差异文件 (MAXAGE:1表示为一天内有异动的文件)
    robocopy d:wwwroot /s /MAXAGE:1 /log:d:backupwwwrootbackup.log d:backupwwwroot


   3.对应网络磁盘机
    net use b: \x3550backup 密码 /user:账号
   
   4.将差异文件压缩备份到网络磁盘去
    "c:Program Files7-Zip7z.exe" a b:wwwroot_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.7z d:backupwwwroot
   
   5.删除备份所产生的差异文件及目录
    rmdir d:backup /s/q
   
   6.删除网络磁盘机对应
    net use /delete b:

◎ 我是我,叶子 -- Robocopy 实用的一些范例设定 2013-3-18

【文件同步备份软件】微软牌 SyncToy
http://www.dotblogs.com.tw/bowwowxx/archive/2010/04/27/14865.aspx

Robocopy
http://ithelp.ithome.com.tw/question/10030243
http://ss64.com/nt/robocopy.html
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
http://technet.microsoft.com/zh-tw/magazine/2006.11.utilityspotlight.aspx
http://ithelp.ithome.com.tw/question/10036198?tag=nl.daily
http://forum.icst.org.tw/phpbb/viewtopic.php?f=10&t=682
http://ithelp.ithome.com.tw/question/10057195?tag=nl.daily
D:>robocopy w:backup d:upload *.aaa /maxage:1

Winrar 的手册: http://acritum.com/winrar/manual/index.html
寄信的参数: Switch -IEML[.][addr] - send archive by email

set path=C:Program FilesWinRAR.;%path%
RAR a D:backup*.rar D:backup*bak
copy D:backup*.rar z:.
del /Q D:backup*.rar

RAR a D:backup*.rar D:backup*bak

可以用 /MIR 这个参数作2个分享数据夹的同步。
robocopy "soruce dir" "destination dir" /MIR

robocopy C:tempSite1 Z:Site1wwwroot *.* /S /XF *.cs *.tmp *.dbg
        *.tmpl *.sln *.csproj *.webinfo /XD .svn _svn /PURGE >> output.log

       
           string server = (string)((Pair)_asyncRequestState._extraData).First;
           ProcessStartInfo procInfo = new ProcessStartInfo();

           // run Robocopy batch file
           procInfo.UseShellExecute = true; //If this is false, only .exe's can be run.

           procInfo.WorkingDirectory = Settings.ProdPubBatchPath;
           procInfo.FileName = Settings.ProdPubBatchFile; // Program or Command to Execute.

           procInfo.Arguments = string.Format("{0} {1}", server, Settings.StagingRootFolder);
           procInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

           CheckStatus();
           UpdateStatus(server, new PublishStatus(server, SR.Copying, null));

           System.Diagnostics.Trace.WriteLine(SR.CopyStartedLogMsg(server, Utility.Now()));
           proc = Process.Start(procInfo);
           proc.WaitForExit();
           System.Diagnostics.Trace.WriteLine(SR.CopyEndedLogMsg(server, Utility.Now()));

           UpdateStatus(server, new PublishStatus(server, SR.Copied, SR.WarmingUp));

          
@Echo Off
@set log={如果你要Log档的话,把Log档的文件名写在这}
@set SourceFolder={RAR的存放目录}
@set DestinationFolder={RAR解开后的存放目录}
@set FtpDownloadFolder={下载档的存放目录}
@set UnRARProgram={UnRAR的程序本体‘exe档完全路径’}
@set FTPShell={刚刚的那个纯文字档}
@Echo >> %log%

@Echo DateTime now : %date% %time% >> %log%
ftp -s:%FTPShell% >> %log%
@Echo ---------------------------------------- >> %log%

@Echo DateTime now : %date% %time% >> %log%
%UnRARProgram% e -o+ -sm0 -ilog %DestinationFolder%[errmsg].txt %FtpDownloadFolder%*.rar %DestinationFolder% >> %log%
@Echo ---------------------------------------- >> %log%

@EXIT

批次命令:特殊符
• 括号:( ..... )
• pipe : |
• 导向: > >> <
• 特殊符避开:
o & ()[]{}^=;!'+,`~ 加""表示为纯符,失去特殊意义
o &<>()@^| 加^表示为自身符,失去特殊意义
• 注意:batch档中把%视为特殊符
o 要使用%的符者,要写成%%才行
o 命令列中的 %i ,在Batch中要写成%%i
o 命令列中的3%2,在 Batch中要写成3%%2
批次命令: For
• 重复性处理
o for %i in (monkey dog monkey) do @echo I love %i
• 显示目录中的特定文件
o for %j in (%windir%*.txt) do type %j
• 从1显示到100
o for /L %i in (1,1,100) do echo %i
• 列出目前所有的目录
o for /D %i in (*) do echo %i

For /f 的使用!!!
• 将指定文档逐行显示
o for /f %i in (%windir%system32eula.txt) do @echo %i
• 剖析文字档,抓出第2、3个区块
o for /f “delims=, tokens=3,7" %i in (%windir%svcpack.log) do @echo %i %j
• 剖析字符串
o for /f "tokens=1,2,3,4" %i in ("my name is jtchen") do @echo your %j is %l, welcome!!
• 将执行结果视为文档,进行剖析
o for /F %i in ('dir/b/ad') do echo %i
o 如果不要剖析呢?? (即希望整行输出)
• 剖析输出:秀出目前的环境变量
o for /f "delims== tokens=1" %a in ('set') do @echo %a

批次命令:流程控制
• if, else
o if %NUMBER_OF_PROCESSORS%==1 echo you've only one processor
o if not "%OS%"=="" @echo your os is %os%
o if "%abc%"=="" (echo nothing) else (echo yes)
 How about if "%abc%"=="" echo nothing else (echo yes)
o if /i "a"=="A" echo a is the same as A
• 跳至:goto :label
• 暂停:pause

Example
:startpoint
set choice=2
if %choice%==1 (
dir /w
) else if %choice%==2(
type c:boot.ini
) else (
goto :startpoint
)
:What's the result ?

实践:菜单系统
What do you want (1/2/3/4) ?
1.列出本台电脑windows目录下,所有S开头的子目录。
2. 找出windowssystem32eula.txt中,所有含 Microsoft 的文字行,排序后分页输出显示。
3. 再来一次
4. 离开。


Yadis!Backup

★★★Microsoft Sync Framework 2.0 Software Development Kit (SDK)
http://www.microsoft.com/downloads/details.aspx?FamilyID=89adbb1e-53ff-41b5-ba17-8e43a2e66254&displaylang=en
http://msdn.microsoft.com/en-us/sync/bb887623.aspx

★★★Cobian Backup
http://www.educ.umu.se/~cobian/cobianbackup.htm
http://img402.imageshack.us/img402/5853/backupp.jpg


~ THE END ~