If you want to fully rename a host, you must (assuming Ubuntu standard
install):

1. Edit the /etc/backuppc/hosts
2. Rename any /etc/backuppc/hostname.pl and .pl.old files
3. Rename the directory in /var/lib/backuppc/pc/

Attached is my bash script to do this with some error checking.

Regards,
Tyler

On 2011-11-24 11:47, Sorin Srbu wrote:
> Hi all,
> 
> The recent ClientNameAlias-hint I got on this list, got me thinking a bit.
> 
> Suppose I want to change the already set hostname from the anonymous 
> "machine001.domain.local" to "adminstation", can I do that somehow, without 
> botching the old backed up files for "machine001.domain.local"?
> 
> Any gotchas'?
> 
> Thanks.
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure 
> contains a definitive record of customers, application performance, 
> security threats, fraudulent activity, and more. Splunk takes this 
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> 
> 
> 
> _______________________________________________
> BackupPC-users mailing list
> [email protected]
> List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
> Wiki:    http://backuppc.wiki.sourceforge.net
> Project: http://backuppc.sourceforge.net/

-- 
"The map is not the territory."
   -- Alfred Korzybski
#!/bin/bash
# 2010-12-06 tyler
AUTHOR="[email protected]"
NAME=$(basename $0)
VERSION="1.1.2"
DESC="Rename a BackupPC host."

# defaults
BACKUPPC_CONF_DIR="/etc/backuppc"
BACKUPPC_CONF_FILE="$BACKUPPC_CONF_DIR/config.pl"
BACKUPPC_HOSTS_FILE="$BACKUPPC_CONF_DIR/hosts"

die() {
        OUTPUT=$@
        [ -n "$OUTPUT" ] && printf "$OUTPUT\n" >&2
        exit 1
}

VersionAndExit() {
        printf "$NAME version $VERSION, by $AUTHOR\n"
        exit 0
}

UsageAndExit() {
        if [ -n "$2" ] ; then printf "$2\n\n" ; fi
        printf "\
Usage: $NAME [options] OLDNAME NEWNAME\n\
$DESC\n\
Options:\n\
  -n        dry run (don't act)\n\
  -v        verbose\n\
  -h        display help\n\
  -V        display version\n\
"
        exit $1
}

while getopts ":hVnv" options; do
   case $options in
      h ) UsageAndExit 0;;
      V ) VersionAndExit 0;;
      n ) echo "Dry run, no changes will be made." ; DRYRUN="-n";;
      v ) VERBOSE="-v";;
      * ) UsageAndExit 1 "Option unknown: -$OPTARG";;
   esac
done

if [ -f "$BACKUPPC_CONF_FILE" ] ; then
    BACKUPPC_TOPDIR=$(grep '$Conf{TopDir}' "$BACKUPPC_CONF_FILE" | sed "s/^.*= 
'//;s/';$//")
else
    die "$BACKUPPC_CONF_FILE not found"
fi

# Clear $@ of switches
shift $(($OPTIND - 1))
if [ -z "$1" -o -z "$2" ] ; then
   UsageAndExit 1
fi

# sanity checks
if [ \! -f "$BACKUPPC_HOSTS_FILE" -o \! -w "$BACKUPPC_HOSTS_FILE" -o \! -r 
"$BACKUPPC_HOSTS_FILE" ] ; then
   die "Cannot read or write to $BACKUPPC_HOSTS_FILE, or it is not a file. 
Aborting."
fi
if [ \! -d "$BACKUPPC_TOPDIR" -o \! -w "$BACKUPPC_TOPDIR" -o \! -r 
"$BACKUPPC_TOPDIR" ] ; then
   die "Cannot read or write to $BACKUPPC_TOPDIR, or it is not a directory. 
Aborting."
fi
grep -q "^$1[   ]" "$BACKUPPC_HOSTS_FILE" || die "$1 not found in 
$BACKUPPC_HOSTS_FILE. Aborting."
grep -q "^$2[   ]" "$BACKUPPC_HOSTS_FILE" && die "$2 already exists in 
$BACKUPPC_HOSTS_FILE. Aborting."
cd "$BACKUPPC_CONF_DIR" || die "Cannot change to $BACKUPPC_CONF_DIR"

# hosts - doesn't sort file
[ -n "$VERBOSE" ] && echo "Replacing $1 with $2 in $BACKUPPC_HOSTS_FILE"
if [ -z "$DRYRUN" ] ; then
   cp -af "$BACKUPPC_HOSTS_FILE" "$BACKUPPC_HOSTS_FILE.old"
   sed -i "s/^$1[       ]/$2    /" "$BACKUPPC_HOSTS_FILE" || die "sed 
replacement failed on $BACKUPPC_HOSTS_FILE"
fi

# per-host configs
[ -n "$VERBOSE" ] && echo "Renaming any per-host configuration files in 
$BACKUPPC_CONF_DIR"
if [ -f "$1.pl" ] ; then
   rename $VERBOSE $DRYRUN "s/$1/$2/" "$1.pl" || die "Can't rename 
$BACKUPPC_CONF_DIR/$1.pl"
fi
if [ -f "$1.pl.old" ] ; then
   rename $VERBOSE $DRYRUN "s/$1/$2/" "$1.pl.old" || die "Can't rename 
$BACKUPPC_CONF_DIR/$1.pl.old"
fi

# backup directory
[ -n "$VERBOSE" ] && echo "Renaming directory in $BACKUPPC_TOPDIR/pc"
if [ -z "$DRYRUN" ] ; then
   mv $VERBOSE "$BACKUPPC_TOPDIR/pc/$1" "$BACKUPPC_TOPDIR/pc/$2" || die "Can't 
move $BACKUPPC_TOPDIR/pc/$i to $2"
fi
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
BackupPC-users mailing list
[email protected]
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/

Reply via email to