Saving, Erasing, Restoring and Backing up Configuration

As you already know, any change to the configuration is made to the running-config, which is different from the startup-config that is loaded at the boot up. What this means is that if you do not save the running-config to the NVRAM as startup-config, all changes will be lost on reboot!

To save the running-configuration to NVRAM, you can use the copy command in the privileged exec mode. The copy command expects two parameters – the source and the destination. In this case, the source is the running-config and the destination is the startup-config, so the command that you will need to use is copy running-config startup-config as shown below:

myRouter#copy running-config startup-config
Destination filename [startup-config]?
Building configuration…
[OK]

Now consider a situation where you made changes to the running-config but want to discard them. Remember that changes to the running-config are immediate. So either you can negate all changes one by one or simply copy the startup config to running-config using the copy command. This time, simply reverse the source and destination as shown below:

myRouter#copy startup-config running-config
Destination filename [running-config]?

1172 bytes copied in 0.972 secs (1206 bytes/sec)

Apart from copying the config between running and startup, you can also copy the config to a TFTP server in the network for backup purpose. You need to backup the config so that you have a copy to use in case the router crashes and you need to replace it. You can again use the copy command by replacing the destination with tftp: as shown below:

myRouter#copy running-config tftp:
Address or name of remote host []? 192.168.1.40
Destination filename [myrouter-confg]? [enter]
!!!
1172 bytes copied in 0.972 secs (1206 bytes/sec)

Notice in the example above that after the command, you are prompted for the IP address of the TFTP server and the file name. You can press enter to use the default file name or provide a different one.

Similarly, you can copy the config from a TFTP server to the running-config by reversing the above command as shown below:

myRouter#copy tftp running-config
Address or name of remote host []? 192.168.1.40
Source filename []? myrouter-confg
Destination filename[running-config]? [enter]
Accessing tftp://192.168.1.40/myrouter-confg…
Loading myrouter-confg from 192.168.1.40 (via FastEthernet0/0): !!!
[OK – 1172 bytes]
1172 bytes copied in 8.134 secs (144 bytes/sec)

If you want to clear the configuration and start afresh, you can erase the startup-config and reload the router. To erase the startup-config, use the erase startup-config command in the privilege exec mode as shown below:

myRouter#erase startup-config
Erasing the nvram filesystem will remove all configuration files! Continue? [confirm]
[OK]
Erase of nvram: complete

To reboot the device, use the reload command in the privilege exec mode as shown below:

myRouter#reload

System configuration has been modified. Save? [yes/no]: no
Proceed with reload? [confirm]y

If the configuration is not saved, the router will prompt you to save the configuration when you enter the reload command. Type no and press enter to not save the configuration and reload with an empty NVRAM. When the devices comes up, there will be no configuration on it and you can start over.

Working with IOS files and IOS File System (IFS)

Similar to how the configuration can be copied around, the IOS file that is used by devices can be backed up or restored or simply changed using the copy command. Remember that IOS file is saved in the flash memory. To copy the file currently used by the router to a TFTP server, use the copy flash: tftp: command as shown below:

myRouter#copy flash: tftp:
Source filename []? c1841-advipservicesk9-mz.124-25e.bin
Address or name of remote host []? 192.168.1.40
Destination filename [c1841-advipservicesk9-mz.124-25e.bin]?
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23348556 bytes copied in 230.972 secs (101088 bytes/sec)

To copy an image from the TFTP server to the flash memory, reverse the above command as shown below:

myRouter#copy tftp: flash:
Address or name of remote host []? 192.168.1.40
Source filename []? c1841-entbase-mz.124-24.T5.bin
Destination filename [c1841-entbase-mz.124-24.T5.bin]?
Accessing tftp://192.168.1.40/c1841-entbase-mz.124-24.T5.bin…
Loading c1841-entbase-mz.124-24.T5.bin from 192.168.1.40 (via FastEthernet0/0): !
%Error copying tftp://192.168.1.40/c1841-entbase-mz.124-24.T5.bin (Not enough space on device)

Notice the error in the above output? It shows that the file was not copied because there is no space left in the flash memory. So before copying the new file, you will need to free up some space. You can check the contents of the flash memory using the dir command in the privileged exec mode as shown below:

myRouter#dir
Directory of flash:/

1  -rw-    23348556  Feb 23 1907 16:27:44 +00:00  c1841-advipservicesk9-mz.124-25e.bin

To free up some space you can delete some the existing files using the delete command.  Since there is only a single file in the flash currently, it has to be deleted as shown below:

 myRouter#delete flash:c1841-advipservicesk9-mz.124-25e.bin
Delete filename [c1841-advipservicesk9-mz.124-25e.bin]?
Delete flash:/c1841-advipservicesk9-mz.124-25e.bin? [confirm] 

Now that you have free space, try the copy command again:

myRouter#copy tftp: flash:
Address or name of remote host [192.168.26.121]? 192.168.1.40
Source filename [c1841-entbase-mz.124-24.T5.bin]?
Destination filename [c1841-entbase-mz.124-24.T5.bin]?
Accessing tftp://192.168.1.40/c1841-entbase-mz.124-24.T5.bin…
Loading c1841-entbase-mz.124-24.T5.bin from 192.168.1.40 (via FastEthernet0/0): !!!!!!!!!!!!!!
[OK – 28532596 bytes]

28532596 bytes copied in 211.228 secs (135080 bytes/sec)

The two commands that you used above, dir and delete are examples of commands that are used to manage the IOS File System (IFS). Even copy is similarly a command to manage the IFS. There are various other commands that can be used to manage the IFS. Some of them are discussed below:

  • show file – This command will give you few details such as file type and size about any file in the IFS. An example is shown below:
myRouter#show file information flash:c1841-advsecurityk9-mz.124-23.bin
flash:c1841-advsecurityk9-mz.124-23.bin:
type is image (elf) []
file size is 21177448 bytes, run size is 21343132 bytes
Runnable image, entry point 0x8000F000, run from ram
  • erase – This command as you already know, can be used to delete the contents of the NVRAM.
  • format – This command is used to erase ALL contents of the flash.
  • mkdir –  This command is used to create a sub-directory in the IFS. An example is shown below:

myRouter#mkdir test
Create directory filename [test]?
Created dir flash:test

myRouter#dir
Directory of flash:/

1  -rw-    21177448   Sep 7 2011 00:12:50 +00:00  c1841-advsecurityk9-mz.124-23.bin
2  drw-           0  Jan 21 2012 14:09:34 +00:00  test

31936512 bytes total (10752000 bytes free)

  • cd – This command is used to move to a sub-directory or move back to parent directory on IFS. For example, cd test will take you inside the sub-directory created above.
  • pwd – This command can be used to find the name of directory you are currently in. An example is shown below:
myRouter#pwd
flash:
myRouter#cd test
myRouter#pwd
flash:/test/
myRouter#cd ..
myRouter#pwd
flash:/
  • rmdir – This command can be used to delete a directory.
  • copy – Similar to how you copied an IOS file to the flash (IFS), you can copy any file to IFS. For example, you can copy the running-config to the IFS as shown below:

myRouter#copy running-config flash:/backup.conf
Destination filename [backup.conf]?

2647 bytes copied in 1.516 secs (1746 bytes/sec)

myRouter#dir
Directory of flash:/

1  -rw-    21177448   Sep 7 2011 00:12:50 +00:00  c1841-advsecurityk9-mz.124-23.bin
2  drw-           0  Jan 21 2012 14:09:34 +00:00  test
3  -rw-        2647  Jan 21 2012 14:13:00 +00:00  backup.conf

  • more – This command can be used to read the contents of a text file that exists on the IFS. For example, you can read the contents of the backup.conf file created in the previous step as shown below:
myRouter#more backup.conf
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname myRouter
!
–output truncated–

In case you have enough free space in the flash memory, you can have multiple IOS files there. By default, the first file that the system encounters is used for booting. You can specify the IOS file that want the system to load to boot up, using the boot system command in the global configuration mode as shown below:

myRouter(config)#boot system flash c1841-entbase-mz.124-24.T5.bin