backup(CMD) 19 June 1992 backup(CMD) Name backup - back up one or more files from one disk onto another Syntax backup source destination-drive: [/s] [/m] [/a] [/f[:size]] [/d:date [/t:time]] [/l[:[drive:][path]logfile]] Description You can back up files onto either a hard disk or floppy disk(s). Files can also be backed up from one floppy disk onto another, even if the disks have different numbers of sides or sectors. MS-DOS displays the name of each file it backs up. Parameters source Specifies the location of files you want to back up. source can consist of a drive letter and colon, a directory name, a filename, or a combination. destination-drive: Specifies the drive that contains the disk on which you want to store any backup files. The backup files are stored in the BACKUP.nnn and CONTROL.nnn files. That is, backup assigns the names BACKUP.001 and CONTROL.001 to the files it creates on the first backup disk you use, BACKUP.002 and CONTROL.002 to the files it creates on the second backup disk, and so on. Switches /s Backs up the contents of all subdirectories. /m Backs up only files that have changed since the last backup, and turns off the archive attribute of the original files. /a Adds backup files to an existing backup disk without deleting existing files. (The /a switch is ignored if the existing backup disk contains backup files that were created by using the backup command from MS-DOS version 3.2 or earlier.) /f[:size] Formats the backup disk to the size you specify. (The format command must be present in the current path.) With this switch, you direct backup to format floppy disks that do not match the default size of the drive. The backup command formats an unfor- matted destination disk even if you do not specify the /f switch. When backup finishes formatting, it begins backing up files onto the last disk it formatted. size specifies the size in kilobytes of the disk to be formatted. If you do not specify size, the /f switch uses the default size of the drive. The following list shows the valid values for size and a brief description of each size: 160 or 160k or 160kb 160K, single-sided, double-density, 5.25-inch disk 180 or 180k or 180kb 180K, single-sided, double-density, 5.25-inch disk 320 or 320k or 320kb 320K, double-sided, double-density, 5.25-inch disk 360 or 360k or 360kb 360K, double-sided, double-density, 5.25-inch disk 720 or 720k or 720kb 720K, double-sided, double-density, 3.5-inch disk 1200 or 1200k or 1200kb or 1.2 or 1.2m or 1.2mb 1.2-MB, double-sided, quadruple-density, 5.25-inch disk 1440 or 1440k or 1440kb or 1.44 or 1.44m or 1.44mb 1.44-MB, double-sided, quadruple-density, 3.5-inch disk 2880 or 2880k or 2880kb or 2.88 or 2.88m or 2.88mb 2.88-MB, double-sided, 3.5-inch disk /d:date Backs up only files modified on or after the specified date. The date format depends on the setting you are using for the country command. /t:time Backs up only files modified at or after the specified time. The time format depends on the setting you are using for the country command. Do not use the /t switch without the /d switch. /l[:[drive:][path]logfile] Creates a log file and adds an entry to that file to record the backup operation. If you do not specify a location for the log file, backup puts the file in the root directory of the source drive. If you do not specify logfile, backup names the file BACKUP.LOG. You should not specify a removable drive (such as a floppy disk drive) for this parameter; but once the backup is complete, you can copy the log file to a floppy disk. Notes Backing up onto a disk with files Unless you use the /a switch, backup deletes old files (including read- only files) from a backup disk before adding new files to it. Backup log file If you use the /l switch and do not specify a name and location for the log file, the backup command adds a file named BACKUP.LOG to the root directory of the source drive. If the BACKUP.LOG file already exists, backup adds the current entry to the file. A backup log-file entry uses the following format: + The date and time of the backup appear on the first line. + Each filename appears on a separate line with the number of the backup disk that contains the file. The backup log file can assist you later, when you need to identify the files you want to restore. The restore command always returns a file to the original directory or subdirectory recorded in the backup log, creat- ing the subdirectory if necessary. Labeling backup disks It is important to label and number backup disks consecutively. As each disk is filled, backup prompts you for the next disk. When you restore files, you need to insert the backup disks into the disk drive in the same sequence. To check the sequence of backup disks (MS-DOS version 3.3 or later), use the dir command to check the disk number. Backup and system files The backup command cannot back up the system files IO.SYS, MSDOS.SYS, and COMMAND.COM. You can use the sys command to copy these files onto a floppy disk. Using an old version of the restore command You cannot use an old version of the restore command (MS-DOS version 3.2 or earlier) for files backed up with MS-DOS version 3.3 or later. If you attempt this, MS-DOS displays the following message: Source does not contain backup files This error occurs because the format of old backup files differs from the format of files backed up with MS-DOS versions 3.3 and later. Using backup with networks or redirected drives or directories If you are sharing files on a network, you can back up only those files to which you have access. You should not use backup with a drive that has been redirected with the assign, join, or subst command. If you do, the restore command may not be able to restore the files. Backup exit codes The following list shows each exit code and a brief description of its meaning: 0 The backup was successful. 1 No files were found to back up. 2 Some files were not backed up because of file-sharing con- flicts. 3 The user pressed CtrlC to stop the process. 4 The process stopped because of an error. You can use the errorlevel parameter on the if command line in a batch program to process exit codes returned by the backup command. For an example of a batch program that processes exit codes, see the following ``Examples'' section. Examples Suppose you want to back up all the files in the \USER\SMITH directory on drive C onto a blank, formatted disk in drive A. To do so, type the fol- lowing: backup c:\user\smith\*.* a: Suppose you need to back up all files in the \USER\SMITH directory on drive C onto a 720K floppy disk in drive B. If the floppy disk is unfor- matted, backup formats it before backing up any files. Because the /s switch is not specified in the following command, files in subdirectories are not backed up: backup c:\user\smith\*.* b: /f:720k To write a simple batch program named SMITH that supports the backup command's exit codes and the /s switch, you can type the following com- mands by using MS-DOS Editor: echo off rem Smith's backup command backup c:\user\smith\*.* b: /s if errorlevel 4 goto error if errorlevel 3 goto abort if errorlevel 2 goto conflict if errorlevel 1 goto no_files if errorlevel 0 goto success :error echo Backup stopped the process due to an error goto exit :abort echo You just pressed CTRL+C to stop the backup goto exit :conflict echo One or more files were not backed up due to a sharing conflict goto exit :no_files echo Sorry, but there were no files to backup goto exit :success echo The backup was successful goto exit :exit For more information about using the if command in batch programs, see the if(CMD) command. Related command For information about restoring a backup file, see the restore(CMD) com- mand.