Skip to content

Building a reliable pkgacct/restorepkg pipeline for routine account moves

pkgacct and restorepkg are the building blocks; the pipeline wraps them with verification, logging, and rollback so account moves stop being one-offs.

Account moves between WHM servers are a recurring event in any growing fleet — load balancing, customer requests, hardware refreshes. Each one becomes a unique mini-project if the team only has the raw pkgacct and restorepkg commands. A wrapper pipeline that handles verification, atomic transfer, and rollback turns the move into a routine the team can run in any order without surprises.

What’s happening

The raw shape of an account move is: pkgacct on the source, rsync the archive to the destination, restorepkg on the destination, verify, and clean up the source after a soak period. Each step can fail; some failures leave the customer in a half-moved state where their DNS points one way, their files exist on both servers, and their mail queues are split. The pipeline’s job is to make each step idempotent and to fail before committing if any pre-condition is unmet.

How to verify

For each stage of the pipeline, the verification commands:

pkgacct user=acme --skipbwdata
ls -lh /home/cpmove-acme.tar.gz
tar tzf /home/cpmove-acme.tar.gz | head -20
ssh dest "whmapi1 list_users | grep acme"
ssh dest "df -h /home"
whmapi1 accountsummary user=acme
ssh dest "whmapi1 accountsummary user=acme"

The archive size and content list confirm pkgacct produced a usable archive. The destination’s user list and disk space confirm the destination can receive. Side-by-side accountsummary outputs after restore confirm equivalence.

The fix

The pipeline as a single script:

#!/usr/bin/env bash
set -euo pipefail
SRC_USER="${1:?usage: move-account <user> <dest-host>}"
DEST="${2:?}"
ARCHIVE="/home/cpmove-${SRC_USER}.tar.gz"

# 1. Pre-checks
whmapi1 accountsummary user="$SRC_USER" >/dev/null
ssh "$DEST" "whmapi1 list_users | grep -qx '$SRC_USER'" && { echo "FAIL: $SRC_USER already on $DEST"; exit 1; }

# 2. Package
pkgacct user="$SRC_USER" --skipbwdata
test -s "$ARCHIVE"

# 3. Transfer
rsync -avP "$ARCHIVE" "${DEST}:/home/"

# 4. Restore
ssh "$DEST" "restorepkg --user=$SRC_USER --owner=$(whmapi1 accountsummary user=$SRC_USER --output=json | jq -r '.data.acct[0].owner') $ARCHIVE"

# 5. Verify
local_summary=$(whmapi1 accountsummary user="$SRC_USER" --output=json | jq -r '.data.acct[0] | "\(.plan) \(.diskquota)"')
remote_summary=$(ssh "$DEST" "whmapi1 accountsummary user=$SRC_USER --output=json" | jq -r '.data.acct[0] | "\(.plan) \(.diskquota)"')
[[ "$local_summary" == "$remote_summary" ]] || { echo "FAIL: post-restore mismatch"; exit 2; }

# 6. Suspend source (don't terminate yet; soak period)
whmapi1 suspendacct user="$SRC_USER" reason="Migrated to $DEST $(date +%F) — pending cleanup"
echo "OK: $SRC_USER moved to $DEST. Source suspended pending cleanup."

Each step has a verification gate. Failure at any step aborts cleanly — source account remains in its prior state, partial state is not committed.

  1. Wrap the pipeline in idempotency checks so re-running with the same user is safe — pre-check refuses if the destination already has the account.
  2. Soak before cleanup. The source account stays suspended for 14 days after move; if the customer reports an issue, unsuspending on the source is instant.
  3. For DNS, update zones after step 6 — separate from the account move so DNS rollback is independent.
  4. Log every move to a central place: who initiated, source, destination, time, archive size, verification result. This is your audit trail.

Routine account moves are exactly the kind of repetitive operational work Stack Harbor’s cPanel server management practice automates so engineers spend time on the moves that need judgement, not the ones that need typing.