Results 1 to 3 of 3

Thread: Backup all settings form home directory

  1. #1
    Join Date
    Nov 2006
    Location
    Cairo, Egypt
    Beans
    300

    Backup all settings form home directory

    I made this little script to backup all the settings stored in my home directory. This script will backup only the settings and will exclude the following:

    - Visible Files and directories that don't start with "." (i.e files like music) that are present on the top level of your home directory tree. These files and directories can be listed by typing the command:

    Code:
    ls ~
    - Unecessary files like cache and history. These are defined in the variable exclude_pattern within the script.


    How to run the script:

    1. Copy the script below to a file and name it home-bakcup.sh or any name you want.

    Code:
    #!/bin/sh
    
    # This script will backup the config files in the home directory to
    # a file $backup_file stored in $target
    
    
    # backup filename
    backup_file=backup.tar.gz
    
    # directory where backup.tar.gz will be stored
    target=$HOME
    
    # any filename containig any keyword form this variable
    # in it's pathname will be excluded
    exlude_pattern="cache gnome log recently serverauth thumb xsession-errors snapshot Snapshot tmp Temp temp history History _bak Cache Log gconf trash Trash"
    
    # any filename resembling an exact keyword form this variable
    # will be excluded
    exclude_name=`ls $HOME`
    
    # define more files to backup
    #include="/etc/fstab /etc/apt/sources.list /etc/X11/xorg.conf /etc/resolve.conf /etc/apt/sources.list"
    
    tar cvzp --exclude=*`echo $exlude_pattern | sed 's/ /* --exclude=*/g'` --exclude=`echo $exclude_name | sed 's/ / --exclude=/g'` --exclude=${backup_file} -f ${target}/backup.tar.gz $HOME $include

    2. Make the script excutable:

    Code:
    chmod u+x /path/to/home-backup.sh
    3. To backup your settings type:

    Code:
    /path/to/home-backup.sh
    4. To restore you settings type:

    Code:
    sudo tar xvpf ~/backup.tar.gz  --same-owner -C /


    Notes:

    - This script primarily saves the settings in the user's home directory. However if you want to backup some other files like fstab or xorg.conf, you can do so by uncommenting the include variable and adding the full name of the file you want to backup:

    Code:
    include="/etc/fstab /etc/apt/sources.list /etc/X11/xorg.conf /etc/resolve.conf /etc/apt/sources.list"
    Or if you want to backup the entire /etc :

    Code:
    include="/etc"
    - The contents of the include variable must be enclosed within double quotes.

    - If for some reason any of the files on your home directory is not readable (e.g. owned by root), the script may fail to complete unless you run it with sudo:

    Code:
    sudo /path/to/home-backup.sh
    - When restoring we must use sudo if we backed up any of the file in /etc
    Last edited by capink; December 31st, 2007 at 06:13 PM.

  2. #2
    Join Date
    Apr 2011
    Location
    di kostan
    Beans
    26
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Backup all settings form home directory

    wow great...
    maybe sometimes very usesfull

  3. #3
    Join Date
    Jun 2007
    Location
    Waikikamukau, New Zealand
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Backup all settings form home directory

    Did anyone notice when this thread was created?
    Forum DOs and DON'Ts
    Never assume that information you find using a search engine is up-to-date.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •