Source SDK

Source SDK

Không đủ lượt đánh giá
How to automatically backup save files
Bởi Werewolf™
Backing up your files is a really important thing to do for PC's in general, but the built in option in Source SDK is frankly crap.

I personally have never been able to use the autosave files it generates to recover work I have done when SDK has crashed on me. I still keep the option enabled though just as an extra backup source, even though I have a better option in place - a backup script.
   
Giải thưởng
Yêu thích
Đã yêu thích
Bỏ thích
Creating the script
To create a script all you need is a simple text editor. You can use the default Windows notepad, but I recommend using Notepad++[notepad-plus-plus.org].

Open your text editor of choice and save the file as <name>.bat . The .bat at the end is important, because this will save the file as a Batch File[en.wikipedia.org] instead of a text (.txt) document. I suggest you keep this batch file somewhere in your documents folder or wherever you organise your project files.

A script is basically a list of instructions for Windows to carry out whenever it is run. In this case, we are going to use the copy command. Each instruction has to be written on its own line in notepad. Each instruction follows the basic structure of [instruction] [source] [destination].

Note: There are many more commands you can use in batch files, but I will let you research them on your own. For this guide, we only need one; the 'copy' command.

In your file, write 'copy' and leave a space. Browse to wherever you save your .vmf files, but up one folder. So for example if you save your .vmf files in "C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\sourcesdk_content\tf\mapsrc", you'll need to be in the tf folder.

While holding 'Shift', right-click on the folder your save files are in, and click 'Copy as Path'.


Go to your notepad file and paste it in. It should be the full address of the folder, wrapped in quotation marks. Next, go to your destination folder and copy the path for that. Paste that on the same line leaving a space in between.

Your instruction line should look like this:
copy "C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\sourcesdk_content\tf\mapsrc" "C:\Users\Werewolf\Dropbox\Backups\"


This will make it copy everything in the "mapsrc" folder into the folder of your choice. Each time it copies it will overwrite any files with the same name. You can also make it copy specific files by simply adding that files name at the end. So for example I could have it copy the main .vmf file by telling it:
copy "C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\sourcesdk_content\tf\mapsrc\mymap.vmf" "C:\Users\Werewolf\Dropbox\Backups\"

This is case sensitive so has to be spelt correctly, and if you change the file name it will not be able to find the file to copy it.

If you want to make it copy files to more than one location, just add extra lines to the file. Each instruction should be placed on a new line and will run in the order you place the instructions.
copy "C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\sourcesdk_content\tf\mapsrc" "Destination One" copy "C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\sourcesdk_content\tf\mapsrc" "Destination Two"

Once you are happy, save and close the file. It's a good idea at this point to test the script by double clicking the file. You should see a command prompt[en.wikipedia.org] box appear while it copies the files.
Once it disappears, browse to the destination folder(s) you set to make sure everything you wanted copied over correctly. If it is not working correctly, reopen the bat file by right-clicking on it and selecting 'Edit with Notepad'
The Destination Folder
Your choice of destination folder should ideally be to somewhere you backup other files so that if something did happen to your computer, then your files would be stored with the rest of your backed up files.

This could be in another location on the same hard drive, to an external hard drive, or a cloud based service such as Dropbox, Google Drive or OneDrive.

An advantage of using cloud based storage is the added ability to access those files across multiple devices or to share those files with other people. This means not only do you have a backup, but so does anyone you are working with.
Which files to backup?
This is somewhat of an open question with no 'right' answer. It is possible to back up too many files if you are trying to backup a whole directory for example.

To some degree this depends on how much storage space you have in your chosen destination. An external hard drive may have enough to store a copy of everything, while a cloud based system might have a limited storage. For example, the free version of Dropbox only offers 2gb of storage.

At the very least, you'll want the maps .vmf file, which is the main file Hammer uses. However there are related files saved in the same folder:
  • .vmf
  • .bsp (if you haven't yet compiled your map, this won't exist until you do)
  • .log
  • .prt
  • .vmx
It is worth backing up all of these files as well. As we have covered in writing the script, we are copying the entire contents of the folder they are stored in so you don't need to worry about this too much.

Depending on what you want to back up, you may want to make multiple scripts to backup specific files or projects. If you want to back up files relating to a specific project, it would be advisable to save them within a dedicated folder within your mapsrc folder, for example: C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\sourcesdk_content\tf\mapsrc\ctf_2fort\

Custom content should also be backed up. This would include custom materials, sounds, particles, scripts and model files. You may also have miscellaneous files that aren't stored with your games directory that you want to have backed up as well.

Something to consider is having the main map files (.vmf, .bsp, et all) back up more frequently than the supporting custom content, by using two (or more) separate scripts; one for the core files and another for the support files.



Making it automatic
For this we will be using Windows Task Scheduler[en.wikipedia.org] which has some specific options you'll want. While the Task Scheduler program hasn't changed between versions, how you find and access it has.
  • Windows 7
    Open it by going to Start Menu > All Programs > Administrative Tools > Task Scheduler
    If you do not have the "Administrative Tools" folder enabled you can open the Task Scheduler by navigating to Start Menu > Run and typing in the following command (It may help to copy and paste this in)
    control.exe schedtasks
  • Windows 10
    Windows 10 is easier to find and run. Simply navigate Start Menu > Windows Administrative Tools > Task Scheduler
    You can also open the start menu and simply type Scheduler and it will come up in the search results.
Now onto actually setting up the automation. On the right hand side of the screen will be the "Create Basic Task"; click this.


Give the task a name of your choice and a description if you want, then click next


Select how often you want it to run. This is up to you, but I suggest at least Weekly.
After selecting a frequency it will give you options to define that frequency more (such as which days, time, etc)
Note: Don't select a time you are often working on the map! If you happen to work on your maps in the evening, don't have the script run in the evening! Windows will not be able to copy the .vmf file if it's open in Hammer. The easiest way to avoid this is to have the script run when you login to Windows.


When it asks "What action do you want the task to perform?", select the "Start a program" option. It will ask you to define a program/script. Browse to where you saved your script and select it.


You can leave the "Add arguments" and "Start In" fields blank.


The final step will give you an overview of the options you have set. Before you click finish, select the option to open the "Properties Dialog" when you finish.

After you click 'Finish', you'll be presented with the box below. You will want to enable the 'Run with the highest privileges' checkbox, and adjust the 'Configure for:' box to your operating system (by default it goes to Windows 7, even though I created this in Windows 10)


Close and finish! Your script will run at the time and day you set without you having to do anything else.