You are not logged in.

#1 2010-03-10 01:16:10

sw2wolf
Member
From: China
Registered: 2009-06-08
Posts: 99
Website

How to backup Arch ?

I like Arch and use it everyday.  I always keep my arch updated.  Sometimes i worry about hard disk failure.  So i want to backup arch.

Any convenient way is appreciated!


e^(π⋅i) + 1 = 0

Offline

#2 2010-03-10 01:33:01

Ultraman
Member
Registered: 2009-12-24
Posts: 242

Re: How to backup Arch ?

Have you looked into rsync and it's mates?

Offline

#3 2010-03-10 02:05:22

evr
Arch Linux f@h Team Member
Registered: 2009-01-23
Posts: 554

Re: How to backup Arch ?

there are lots of ways to backup your stuff.

http://wiki.archlinux.org/index.php/Backup_Programs

Offline

#4 2010-03-10 03:15:26

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,053

Re: How to backup Arch ?

also, if you would like a little more control over your backup check this out
http://wiki.archlinux.org/index.php/Ful … with_rsync


Hofstadter's Law:
           It always takes longer than you expect, even when you take into account Hofstadter's Law.

Offline

#5 2010-03-10 03:36:22

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: How to backup Arch ?

I use rsync to back up and changes made to /home and /etc onto a second disk upon shutdown. I make hard copies of that stuff on DVDs also.

Offline

#6 2010-03-10 03:39:17

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: How to backup Arch ?

I use this script to back up only selected things with rdiff-backup to encrypted removable disk. There's configuration embedded in it to know where to find the disk, and what to back up, for each machine it runs on. Much of it is specific to me, but hopefully it's a nice example.

#!/bin/bash
# vim:set filetype=sh: *

if [ `id -u` != "0" ] ; then
    echo "You must be root"
    exit 1
fi

case "$(hostname -s)" in
    "asenath")
        role=primary
        diskpart="usb-_Patriot_Memory_07960608B32D3531-0:0-part1"
        ;;
    "akherou")
        role=duplicate
        diskpart="usb-_Patriot_Memory_07960608B32D3531-0:0-part1"
        ;;
    "amaranth")
        role=primary
        diskpart="usb-ST375063_0AS_00E001012641D-0:0-part2"
        ;;
    *)
        echo -e "\e[31m==> Unable to determine machine role for $(hostname -s)\e[0m"
        exit 2
esac

disk="${diskpart%-part*}"

case "$disk" in
    "usb-_Patriot_Memory_07960608B32D3531-0:0")
        disktype=ssd
        disksize=small
        ;;
    "usb-ST375063_0AS_00E001012641D-0:0")
        disktype=hdd
        disksize=big
        ;;
    *)
        echo -e "\e[31m==> Unknown disk ${disk}\e[0m"
        exit 3
esac

echo -e "\e[32m==> Backing up with: disksize=${disksize} role=${role}\e[0m"

logger -t backup "backup started"

while [[ ! -b /dev/mapper/lb ]] ; do
    while [[ ! -b /dev/disk/by-id/${diskpart} ]] ; do sleep 1 ; done
    cryptsetup luksOpen /dev/disk/by-id/${diskpart} lb
done

if [[ $(stat -c "%i" /backup) != "2" ]] ; then
    fsck /dev/mapper/lb || exit 4
    mount /backup || exit 5
fi

sync

case "$disksize" in
    "big")
        backuplist="--exclude /home/ataraxia/.cache \
        --exclude /home/ataraxia/junk \
        --include /boot/grub/menu.lst \
        --include /etc \
        --include /home \
        --include /var/lib/pacman/local \
        --include /var/spool/cron \
        "
        ;;
    "small")
        case "$role" in
            "primary")
                backuplist="--include /home/ataraxia/pkgs/.hg \
                --exclude /home/ataraxia/.cache \
                --exclude /home/ataraxia/junk \
                --exclude /home/ataraxia/music \
                --exclude /home/ataraxia/pkgs \
                --exclude /home/ataraxia/.mozilla/firefox/firefox/42y0m9cw.default/extensions/VMwareVMRC@vmware.com \
                --exclude /home/ataraxia/.thunderbird/z10luhfe.default/global-messages-db.sqlite \
                --exclude /home/ataraxia/.thunderbird/z10luhfe.default/ImapMail \
                --include /boot/grub/menu.lst \
                --include /etc \
                --include /home \
                --include /var/lib/pacman/local \
                --include /var/spool/cron \
                "
                ;;
            "duplicate")
                backuplist="--exclude /home/ataraxia/.cache \
                --exclude /home/ataraxia/.config/chromium \
                --exclude /home/ataraxia/.mozilla \
                --exclude /home/ataraxia/.thunderbird \
                --exclude /home/ataraxia/code \
                --exclude /home/ataraxia/docs \
                --exclude /home/ataraxia/junk \
                --exclude /home/ataraxia/music \
                --exclude /home/ataraxia/pkgs \
                --include /boot/grub/menu.lst \
                --include /etc \
                --include /home \
                --include /var/lib/pacman/local \
                --include /var/spool/cron \
                "
                ;;
            *)
                echo -e "\e[31m==> Disksize \"small\" must have role \"primary\" or \"duplicate\", not ${role}\e[0m"
                exit 6
        esac
        ;;
    *)
        echo -e "\e[31m==> Unknown disksize ${disksize}\e[0m"
        exit 7
esac
        
rdiff-backup \
--exclude-sockets \
--exclude-fifos \
$backuplist \
--exclude '**' \
/ \
/backup/$(hostname -s)

sync

rdiff-backup --list-changed-since 1B /backup/$(hostname -s)
df -h /backup

umount /backup
cryptsetup luksClose lb

if [[ "$disktype" == "hdd" ]] ; then
    sleep 3
    hdparm -Y /dev/disk/by-id/${disk}
fi

logger -t backup "backup finished"

Offline

#7 2010-03-10 04:08:13

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: How to backup Arch ?

Got enough yet?

I'll add one more before you're completely saturated. wink

Every now and then I do full system backups.  Have found it to be useful at times.  Here's a real basic script using go' 'ole tar.  To use, I just chroot from a LiveCD and run it from there.

#!/bin/bash
# full system backup

# Labels for backup name
#PC=${HOSTNAME}
pc=pavilion
distro=arch
type=full
date=`date "+%F"`
backupname=$distro-$type-$date.tar.gz

# Backup destination
backdest=/opt/backup

# Exclude file location
prog=${0##*/} # Program name from filename
bcdir="/home/todd/.bin/root/backup"
exclude_file="$bcdir/$prog-exc.txt"

# Check if chrooted prompt.
echo -n "First chroot from a LiveCD.  Are you ready to backup? (y/n): "
read executeback

if [ $executeback = "y" ]; then
  tar --exclude-from=$exclude_file -czpvf $backdest/$backupname /
fi

Last edited by Gen2ly (2010-03-10 04:08:32)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#8 2010-03-10 10:36:30

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: How to backup Arch ?

Real men don't back up...then cry when they lose everything :'(


neutral

Offline

#9 2010-03-10 18:45:22

Wintervenom
Member
Registered: 2008-08-20
Posts: 1,011

Re: How to backup Arch ?

#!/bin/bash
### System Backup ##############
# Version 0.5 by Scott Garrett #
# Wintervenom [(at)] gmail.com #
################################
backup_label="Backup"

exclude="/dev/shm/rsync-excludes.rc"

excludes=(
  'tmp/*'                     # Temp files.
  'tmp/.*'                    # Hidden temp files.
  '.mozilla/firefox/*/Cache'  # Firefox caches...
  'cookies.sqlite'            # Mozilla-based cookies.
  'formhistory.sqlite'        # Mozilla-based form history.
  '.thumbnails'               # Thumbnail cache.
  '.recently-used.xbel'       # Recent-open history.
  '.ccache'                   # Compiler caches
  'sessionstore.js'           # Firefox session-saves.
  '.gvfs'                     # GNOME virtual filesystem.
    '.local/share/Trash'        # XDG trash.
    '.local/share/user-places*' # Recent-open history.
    '.purple/logs'              # Pidgin/Finch logs.
    '.cache/Thunar/thumbnailers.cache' # Thumbnailer cache.
  '.cache/chromium'           # Chrome cache.
  '*~'                        # Backup/temp files.
)

out () {
  echo ">> $*"
}

stat_done () {
  echo ">> ...done."
}

stat_fail () {
  echo ">> ...failed!"
}

if [ $UID != '0' ]; then
  echo "Must be executed as root user."
  exit 1
fi

out "Mouting backup device ('$backup_label')..."
backup_dev=`readlink -f "/dev/disk/by-label/$backup_label"`
if mount | grep -qF "$backup_dev on"; then
  backup_root=`mount | grep -F "$backup_dev on" | cut -d' ' -f3`
  echo "  - This device seems to already be mounted at '$backup_root'."
  echo '    Do you want to use this, instead (y/N)?'
  echo -n '   << '
  read -n1 confirm
  echo
  [ "$confirm" != 'y' ] && exit 1
else
  backup_root="/mnt/$backup_label"
  mkdir -p "$backup_root"
  if ! mount -o noatime,user "$backup_dev" "$backup_root"; then
    echo '  - Failed to mount device.'
    exit 1
  fi
  echo '  - Device mounted successfully.'
fi

out "Backing up system..."
echo > /tmp/rsync-excludes.rc
for file in ${excludes[@]}; do
  echo "$file" >> "$exclude"
done
rsync -axl -h --progress --delete --delete-excluded --exclude-from="$exclude" /{home,usr,opt,var,*bin,lib*,etc,boot,root,srv} "$backup_root/$HOSTNAME"
mkdir -p "$backup_root/$HOSTNAME/"{dev,sys,proc,tmp,mnt,media}
mkdir -p "$backup_root/$HOSTNAME/var/"{tmp,lock}
chmod 1777 "$backup_root/$HOSTNAME/tmp" "$backup_root/$HOSTNAME/var/"{tmp,lock}
stat_done

out "Backing up package list..."
pacman -Qqe | grep -v "$(pacman -Qmq)" > "$backup_root/$HOSTNAME/pacman.list"
pacman -Qmq > "$backup_root/$HOSTNAME/yaourt.list"
stat_done

out "Unmouting backup partition..."
if umount "$backup_dev"; then
  rmdir "$backup_root/$HOSTNAME"
  rmdir "$backup_root"
else
  echo '  - Could not unmount.';
fi

Last edited by Wintervenom (2010-03-11 09:01:29)

Offline

Board footer

Powered by FluxBB