Linux script to backup multiple slices ?

73 views
Skip to first unread message

Peter Onion

unread,
Jun 9, 2025, 2:20:58 AM6/9/25
to RC2014-Z80
Before I get my bash-scripting head on,  does anyone have a script so that for example :

script /dev/sda 0,1,2,3

will make a backup of the files from slices 0,1,2 and 3 from the disk connected as /dev/sda ?

PeterO


Peter Onion

unread,
Jun 9, 2025, 6:03:10 AM6/9/25
to RC2014-Z80
I've had to copy the versions of the cpmtools from ~/RC2014/RomWBW-3.5.1/Tools/Linux to /usr/local/bin so that they are used in preference to the ones in /usr/bin which don't
work with the slice definitions (even with /etc/cpmtools/diskdefs updated).

No error checking or command line validation, but as a rough proof of concept this works.

------------------------- CUT --------------------------
#!/usr/bin/env bash
# Usage : cpmbackup /dev/sdb CF-1 0 1 2
 
parse_result(){
  local user
  while read line; do

awk -F' ' '{print $6}' | while read user
do
    echo "sCopying files from slice = $slice user = $user"
    mkdir $rootdir/S$slice/U$user
    cpmcp -f wbw_hd1k_$slice $device $user:*.* $rootdir/S$slice/U$user
done
   done
}


device=$1
echo "device = $device"
shift 1
name=$1
echo "name = $name"
shift 1
date=$(date +%Y-%m-%d_%H:%M)

mkdir $name
mkdir $name/$date
rootdir=$name/$date

for slice in "$@"
do
echo "slice = $1";
mkdir $rootdir/S$slice/
parse_result < <(cpmls -f wbw_hd1k_$1 -F $device | grep "Directory For Drive ")

shift 1
done
------------------------------------------------------------

Peter Onion

unread,
Jun 9, 2025, 6:32:02 AM6/9/25
to RC2014-Z80
I spoke too soon.  As with all proof of concepts it's easy to break!  More work needed :-)
PeterO

Peter Onion

unread,
Jun 9, 2025, 6:45:59 AM6/9/25
to RC2014-Z80
In my defense it's been a few years since I wrote any non-trivial bash scripts.
Here's Mk II

#!/usr/bin/env bash
# Usage : cpmbackup /dev/sdb CF-1 0 1 2

parse_result(){
  local user
  while read line; do

      echo "line = $line"
      user=$(echo $line | awk -F' ' '{print $6}')
      echo "slice = $slice user = $user"

      mkdir $rootdir/S$slice/U$user
      cpmcp -f wbw_hd1k_$slice $device $user:*.* $rootdir/S$slice/U$user
   done
}


device=$1
echo "device = $device"
shift 1
name=$1
echo "name = $name"
shift 1
date=$(date +%Y-%m-%d_%H:%M)

mkdir $name
mkdir $name/$date
rootdir=$name/$date

for slice in "$@"
do
echo "slice = $1";
mkdir $rootdir/S$slice/
parse_result < <(cpmls -f wbw_hd1k_$1 -F $device | grep "Directory For Drive ")

shift 1
done

Wayne Warthen

unread,
Jun 9, 2025, 1:13:24 PM6/9/25
to RC2014-Z80
Very nice.  Kind of the reverse of the process that the RomWBW build uses to create disk images.

-Wayne

Reply all
Reply to author
Forward
0 new messages