USU/RS-GIS Labs How to backup your files


How to backup your files using tar

Paul Farrall
  1. tar to file.
  2. tar to tape drive.

    Backup to tar files

    you can use the tar command to write files and directories to an output file or a tape drive. Here are some simple instructions to get you started. For more info type "man tar" at a command prompt Creating tar file

    First choose a name for the output tarfile. This file will contain an archive of all the files you select. The output file name should end in ".tar" like this "my_tar_file.tar" . Now cd to the directory where the files are that you want to tar up and type one of the following:

    To tar up the current directory
    $ tar cvpf my_backup_file.tar .   
    To tar up individual files
    $ tar cvpf my_backup_file.tar file1 file2 file3.....  
    
    

    When the process is complete you will have a file, "my_backup_file.tar" in the current directory. This file contains the contents of all the files you selected. You can move this file wherever you like (floppy, another machine, etc..). You can compress the file by typing:

    $ gzip my_backup_file.tar
    
    This will leave you with a compressed file named "my_backup_file.tar.gz". To uncompress your file type:
    $ gunzip my_backup_file.tar.gz
    
    This will uncompress your file and rename it to "my_backup_file.tar". Listing contents of tar file You can verify that your files are in the tar file by typing:
    $ tar tvpf my_backup_file.tar   # list contents of the tar file
    
    Extracting from tar file You can extract files from the tar file by typing:
    $ tar xvpf my_backup_file.tar   # Extract files from tar file
    

    Be careful with this, because you can overwrite existing files in the current directory. You might want to put the tar file in a temporary directory before extracting from it.

    $ mkdir tar_dir
    $ mv my_backup_file.tar tar_dir
    $ cd tar_dir
    $ tar xvpf my_backup_file.tar
    

    Backup to Tape

    Backing up to the tape drive is very similiar to writing a tar file. You just use the name of the tape drive device instead of a file name. The tape drive on your system will be named /dev/rmt/x where x is 0 or 1. There should be a label on the tape drive, if not try /dev/rmt/0. The tar commands for the tape drive are:

    $ tar cvpf /dev/rmt/x .  # Back up current dir
    $ tar cvpf /dev/rmt/x file1 file2....   # Backup individual files
    $ tar tvpf /dev/rmt/x    # List files on tape
    $ tar xvpf /dev/rmt/x    # Extract files on tape to current dir.
    



    $Id: backup.shtml,v 1.1 2002/02/08 23:34:39 pfarrall Exp $