View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject: MythFrontendBackup?
PostPosted: Fri Sep 14, 2007 12:06 pm 
Offline
Joined: Tue Jul 12, 2005 8:01 am
Posts: 670
Location: Salem, MA
Has anyone written a script for backing up a MythTV frontend-only box? I can manually tar /etc, /root, & /home, but if someone has already written a script, that would be nicer than doing it manually...

_________________
LinHES 8.3, 1 BE, 3 FE


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 12:11 pm 
Offline
Joined: Fri Oct 20, 2006 12:04 pm
Posts: 905
Location: LA, CA
I was thinking about this myself as I'm preparing for the leap to F27 this weekend...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 1:38 pm 
Offline
Joined: Tue Jul 12, 2005 8:01 am
Posts: 670
Location: Salem, MA
me too :D

This message in MythWeb got me to say: "okay it's time":
Quote:
There's guide data until 2007-09-17 19:00 (3 days). WARNING: is mythfilldatabase running?


Good luck.

_________________
LinHES 8.3, 1 BE, 3 FE


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 1:48 pm 
Offline
Joined: Sun Sep 25, 2005 3:50 pm
Posts: 1013
Location: Los Angeles
I've been tinkering with it a bit. I've been modifying the included mythbackup/mythrestore scripts to perform a backup and save it on the MBE. I've only got thru the backup scripts. I have yet to tinker with restore. Here's what I have for backup...

BEWARE UNTESTED CODE! USE AT YOUR OWN RISK!


mythbackup-fe
Code:
#!/bin/bash
set -vx
#----------------------------------------------------------------------------
#. /usr/local/bin/backupcommon || {
. /usr/local/bin/backupcommon-fe || {
    echo "Can not find common settings!"
    exit 1
}
#----------------------------------------------------------------------------

# Play a sound to let you know I'm starting.
play_sound init.wav

# Keep a chain of recent backups,
echo "Starting rollover of old backups, this may take a while..."

[ -f "$BACKUP_TAR" ] && shrink $BACKUP_TAR
backup_roller .9 .8 .7 .6 .5 .4 .3 .2 .1 ''
echo "Rollover completed."

# Now to backup the other files, no fooling around, grab everything in the
# list because you never know what you'll want, and we can always get clever
# about what to restore later...

# gather all the things in the list into a nice tidy bundle
cd /
/bin/tar cvf $BACKUP_TAR $BACKUP_LIST
shrink $BACKUP_TAR

# If you can't read this you've got no business restoring from it anyway.
/bin/chown root:root $BACKUP_TAR*
/bin/chmod go-rwx $BACKUP_TAR*

echo "Sanity checking your backup..."
play_sound testing.wav
# Play a sound to let you know the outcome.
if check_files $BACKUP_LIST ; then
    echo "Backup passes all checks."
    play_sound complete.wav
    exit 0
else
    echo "The backup is bad or already out of date!"
    play_sound fail.wav
    exit 1
fi


backupcommon-fe
Code:
#!/bin/bash
set -vx
#----------------------------------------------------------------------------
BACKUP_LIST="./root ./home ./etc"
RESTORE_LIST="./root ./home ./etc/mythtv/modules ./etc/lirc ./etc/X11/xorg.conf ./etc/asound.conf ./etc/default/aumix ./etc/$
IGNORE_LIST='./home/mythtv/.upgrade
./home/mythtv/.configure
./home/mythtv/.newcard
./root/mythstreamweb.tar
./home/mythtv/.Xauthority
./root/.Xauthority'
BACKUP_DIR="/myth/backup/rfe-2"
BACKUP_EXTRAS="$BACKUP_DIR/backup-rfe-2.list"
RESTORE_EXTRAS="$BACKUP_DIR/restore-rfe-2.list"
BACKUP_TAR="$BACKUP_DIR/savedfiles-rfe-2.tar"
UPDATE_FILES="/usr/local/bin/restore_fixups.sh"
COMPRESSION=".gz"
SOUNDS="/usr/share/sounds"
PLAYER="/usr/bin/aplay"
#----------------------------------------------------------------------------

play_sound () {
    ($PLAYER $SOUNDS/$1 >& /dev/null)&
}

get_extras () {
    extras=""
    for extra in $(/bin/cat $1); do
        case "$extra" in
        ./*) extras="$extras $extra" ;;
        /*) extras="$extras .$extra" ;;
        *) extras="$extras ./$extra" ;;
        esac
    done
    echo "$extras"
}

[ -f "$BACKUP_EXTRAS" ] &&
    BACKUP_LIST="$BACKUP_LIST $(get_extras $BACKUP_EXTRAS)"

[ -f "$RESTORE_EXTRAS" ] &&
    RESTORE_LIST="$RESTORE_LIST $(get_extras $RESTORE_EXTRAS)"

shrink () {
    case "$COMPRESSION" in
    .gz)
        /bin/gzip -9 "$@"
        ;;
    .bz2)
        /bin/bzip2 -9 "$@"
        ;;
    *)
        ;;
    esac
}

expand () {
    case "$*" in
    *.gz)
        /bin/gunzip "$@"
        ;;
    *.bz2)
        /bin/bunzip2 "$@"
        ;;
    -c\ *)
        /bin/cat $2 /dev/null
        ;;
    -t\ *)
        return 0
        ;;
    *)
        echo 1>&2 "Error, unknown file type!"
        return 1
        ;;
    esac
}

single_format () {
    candidates=$(ls -1 "$1.gz" "$1.bz2" "$1" 2>/dev/null)
    case $(echo "$candidates" | wc -l) in
    1)  return 0  # One is good!
        ;;
    0)  echo "Error, no $1 found!"
        return 1
        ;;
    *)  echo "Warning, multiple formats for $1 found!"
        echo "Candidates are: $candidates"
        ;;
    esac
}

compression_type () {
    for compression in .gz .bz2 "" ; do
        if [ -f "$1$compression" ] ; then
            echo "$compression"
            return 0
        fi
    done
    return 1
}

backup_roller () { # Gets the rollover sequence to use.
    prev_i=$1 ; shift
    for i in "$@" ; do
        for c in .gz .bz2 "" ; do
            for f in $BACKUP_TAR ; do
                /bin/rm -f $f$c$prev_i
                if [ -f "$f$c$i" ] ; then
                    echo "Moving $f$c$i to $f$c$prev_i"
                    /bin/mv -f $f$c$i $f$c$prev_i
                fi
            done
        done
        prev_i="$i"
    done
}

# Given "subset A B" return true if is A a subset of B
subset () {
    cnt=$(/usr/bin/diff $1 $2 | /bin/grep '^<' | /usr/bin/wc -l)
    [ "$cnt" -eq 0 ] && return 0
    /usr/bin/diff $1 $2
}

check_files () {
    OBJECT_LIST="$*"
    LIVE_FILES=/tmp/live_files_$$
    SAVED_FILES=/tmp/saved_files_$$

    echo "Checking for the existance of the backup tar file..."
    single_format "$BACKUP_TAR"
    c=$(compression_type "$BACKUP_TAR") ||
        { echo "Error, missing tar file - '$BACKUP_TAR$c'." ; return 1 ; }
    echo "Using file $BACKUP_TAR$c"
    echo "Backup tar file exists. Checking the compression..."
    expand -t $BACKUP_TAR$c ||
        { echo "Error, bad compressed tarball - '$BACKUP_TAR$c'." ; return 1 ; }
    echo "Compression looks OK. Checking backup tar file contents..."

    echo "Generating a list of the backup contents..."
    expand -c $BACKUP_TAR$c | /bin/tar tf - $OBJECT_LIST |
      /bin/sed '/\/$/s///' | /bin/grep -vxF "$IGNORE_LIST" | /usr/bin/sort -u >$SAVED_FILES

    echo "Generating a list of the directory contents..."
    cd /
    /usr/bin/find $OBJECT_LIST \( -type d -or -type f -or -type l \) -print |
      /bin/grep -vxF "$IGNORE_LIST" | /usr/bin/sort -u >$LIVE_FILES

    echo "Comparing directory versus backup contents..."
    case $0 in
    *backup) # backup must contain everything selected from the directories
        subset $LIVE_FILES $SAVED_FILES
        ;;
    *restore) # directories must contain everything selected from the backup
        subset $SAVED_FILES $LIVE_FILES
        ;;
    *)
        /usr/bin/diff $LIVE_FILES $SAVED_FILES
        ;;
    esac
    FILE_STATUS=$?
    /bin/rm $LIVE_FILES $SAVED_FILES
    if [ $FILE_STATUS -eq 0 ] ; then
        echo "Live and saved file lists match."
    else
        echo "Warning, file lists are not identical!"
    fi
    return $FILE_STATUS
}

has_records () {
    filename="$1"
    description="$2"
    if [ $(wc -l < "$filename") -eq 0 ] ; then
        echo "Warning, could not get record counts from $description!"
        return 1
    fi
    if [ $(awk '{cnt+=$2} END {print cnt}' < "$filename") -eq 0 ] ; then
        echo "Warning, total record count from $description is zero!"
        return 1
    fi
    return 0
}

#check_files () {
#    STATUS=0
#    echo
#    check_files "$@" || STATUS=1
#    echo
#    return $STATUS
#}

true # Make sure that this shows success


The main problem I see with this is that on a KnoppMyth upgrade, your NFS mount to your MBE will not be available. I'm kicking around some ideas in my head about how to deal with that, but if anyone has any suggestions, I welcome them.

_________________
Mike
My Hardware Profile


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 7:24 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
What did you have to change in backupcommon? Without auditing the code right now I can't think of anything obvious where the file and db stuff isn't separated out...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 1:11 pm 
Offline
Joined: Tue Jul 12, 2005 8:01 am
Posts: 670
Location: Salem, MA
Well, I just ended up backing it up manually... It would be nice, though, to have a supported frontend backup that essentially backs up the same as the backend but without backing up the database.

_________________
LinHES 8.3, 1 BE, 3 FE


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 8:57 pm 
Offline
Site Admin
Joined: Fri Sep 19, 2003 6:37 pm
Posts: 2659
Location: Whittier, Ca
How the frell is this a hint or tip? You don't ask for hints or tips, you frelling post them.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu