Пакетное резервное копирование команд в разных папках

483
Prasanna Kumar

Я пытаюсь создать резервную копию для сохранения игры Assassins Creed 3 каждые x минут, но папка и ее файлы перезаписываются каждый раз, пожалуйста, предложите мне код, чтобы каждая резервная копия находилась в разных папках. Извините за плохой английский .

cls @echo off color 0C echo. echo Start Backup echo. pause :start cls echo. echo Backup started echo. xcopy "source" "destination" /s /y /e timeout /t 5 goto start 
-1

2 ответа на вопрос

1
WireGuy

You could use time to create a directory name:

set butime=%time:~0,2%%time:~3,2%%time:~6,2% mkdir %butime% 
Я попробовал это сейчас, но проблема в том, что папки создаются на рабочем столе Prasanna Kumar 11 лет назад 0
Ой, извини, это сработало, но я набрал время, а не время, спасибо. Prasanna Kumar 11 лет назад 0
1
Isiah Meadows

If you wouldn't mind making the directories' names based on date and time (which I would think you probably wouldn't mind in this situation), then maybe this batch file would work. Also, this would help automate it a bit. The reason I'm making the check for if the game is running is because there isn't any real reason to make a backup when the game has been off for a while.

  1. Create this batch file:

    @echo off setlocal enabledelayedexpansion enableextensions cls rem Color is taken care of in the task call. %= ============================================================== =% rem * Take this section out if you want it to make backups even when rem * you're not playing the game. echo Checking if game is running... md "%tmp%\cmdtmp" set tmpdir=%tmp%\cmdtmp tasklist /fo csv /nh /fi "imagename eq %NameOfACExectuable%" /fi "status eq running" > "%tmpdir%\tmp.txt" set /p tasklist= < "%tmpdir%\tmp.txt" del "%tmpdir%\tmp.txt" rd "%tmpdir%" /s /q set tasklist= set tmpdir= %= ============================================================== =% set image= for /f "tokens=1 delims=," %%I in (!tasklist!) do ( set tmpvar=%%~I for %%J in (!tmpvar!) do if not defined image set image=%%~xJ rem * The file extension needs checked so image doesn't become rem * set with output saying that no files have been found. rem * This section has to be a bit complicated because there rem * isn't any straightforward way to get an extension out of rem * an environment variable. ) if not defined image goto :eof echo. echo Backup has now started. rem * This is to ensure that the date/time format is consistent rem * (we likely don't use the same date/time format). set X= for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x set datetime=!X:~0,4!!X:~4,2!!X:~6,2!_!X:~8,2!!X:~10,2!!X:~12,2! set bkupdir="%WhereverYouWantToMakeTheBackup%" md "%bkupdir%\savebackup_!datetime!" set thisbkupdir="%bkupdir%\savebackup_!datetime!" xcopy "%WhereYourACGameSaveIs%" "!thisbkupdir!" /e /y /c /q echo. echo Backup completed. Exiting... timeout /t 5 /nobreak exit 
  2. Create a task (there are two routes to do this):

    1. Via Task Scheduler (You probably will have the menu items translated into your native language if Microsoft has any sense at all):
      1. Type taskschd.msc in the search bar int the start menu and hit Enter.
      2. Click "Task Scheduler Library" on the left sidebar and then click "Create a new task" on the right sidebar.
      3. Type the name you want for the task.
      4. Click the "Triggers" tab and click "New..." on the bottom.
      5. Select "At task creation/modification" in the "Begin the task" drop-down menu.
      6. In the Advanced Options area, tick the box that says "Repeat task every:" with the following options:
        • X minutes (your choice here)
        • Duration: Indefinitely
      7. Click the "Actions" tab and click "New..." on the bottom.
      8. Select "Start a program" in the "Action" drop-down menu, if it isn't already selected.
      9. In the "Program/script:" box, type %comspec% /t:0C /c "Drive:\Dir\To\YourBatchFile.bat".
      10. In the "Conditions" tab, make sure nothing is selected. Some of the options, if checked, will quickly and completely negate the point of all of this work, especially if you're using a laptop and both the "Start only if the computer is on AC power" and "Stop if the computer switches to battery power" are checked.
      11. Hit "OK" at the bottom to save the task.
    2. Via command line
      1. Type this into Command Prompt and hit Enter (Replace %DirToBat% with the actual directory):
        schtasks /create /tn WhatYouWantToNameYourTask" /tr "'%comspec%' /t:0C /c \"%DirToBat%\"" /sc minute /mo X 
        Please note that the quotes being passed as arguments to %comspec% MUST be escaped as shown. Also, the number of minutes here are something you can more finely control than in the UI.

One item of note: The batch file is written to stop immediately after seeing that the game isn't running, and it makes the check before making any preparations to back up anything. If you don't want that, then take out the sections marked by commented equal signs: %= ============= =%

Also, feel free to translate the echo lines if you wish.

Похожие вопросы