Recompress clonezilla images from gzip to bzip2

You can adapt this for any compression scheme but I sometimes make backups of systems that lack processing power to justify compressing backups to bz2 on the fly. My solution is to do gz first and recompress the images later on another machine, still keeping them compatible but reducing them in size. Restoring works as if you would have used bz2 from the start.

cat sda1.ntfs-ptcl-img.gz.* | gunzip \
| pbzip2 -c | split -b 4096m - sda1.ntfs-ptcl-img.bz2.

or if you want prettier progress display using pv

cat sda1.ntfs-ptcl-img.gz.* \
| pv -c -N "gz " -s \
$(du -sbc sda1.ntfs-ptcl-img.gz.* | tail -n -1 | awk '{print $1}') \
| gunzip | pv -c -N "raw" \
| pbzip2 -c | pv -c -N "bz2" \
| split -b 4096m - sda1.ntfs-ptcl-img.bz2.

There’s room for improvement and scripting but I think you get the geist of it.

Renaming files from YYMM(DD) to ISO YYYY-MM(-DD)

I wrote a script and decided to try out code display here by posting it. I know tools like rename do this but I like to see what will be done before I go doing it so I am quite fond of generating scripts I can pipe to /bin/sh

Enjoy 🙂

datename-to-iso.sh

#!/bin/sh
find . -depth -regextype egrep -regex '^\..*/[0-9]{4,6}.*' | while read -r file; do
  # YYMMDD becomes YYYY-MM-DD
  newfile=$(echo "$file" | sed -nre '/[0-9]{4,6}(\.|-[0-9]{2}).*/!p' \
    | sed -re \
    's/(^.*)\/([0-9]{2})([0-9]{2})([0-9]{2})([^0-9\/]+$)/\1\/20\2-\3-\4\5/'
  )

  # If not, then YYMM becomes YYYY-MM
  if [ "$newfile" = "$file" ]; then
    newfile=$(echo "$file" | sed -nre '/[0-9]{4,6}(\.|-[0-9]{2}).*/!p' \
      | sed -re \
      's/(^.*)\/([0-9]{2})([0-9]{2})([^0-9\/]+$)/\1\/20\2-\3\4/'
    )
  fi

  # Did we come up with a new filename?
  if [ -n "$newfile" ] && [ "$newfile" != "$file" ]; then
    echo mv -v "\"$file\"" "\"$newfile\""
  fi
done

(updated 2016-09-15)