Friday, 26 September 2014

Time for Bash - No, not #ShellShock

So I have a backup script that I use to backup certain folders on my Mac to an external USB drive: -

#! /bin/bash

# now=$(date +"%d_%m_%Y" +"_" +"%h:%m")
now=`date +%d-%m-%Y-%H-%M-%S`

tar cvzf notes_$now.tar.gz ~/Library/Application\ Support/IBM\ Notes\ Data/*
tar cvzf docs_$now.tar.gz ~/Documents/Docs.ISSW/*
tar cvzf customers_$now.tar.gz ~/Documents/Customers.ISSW/*
tar cvzf personal_$now.tar.gz ~/Documents/Personal/*
tar cvzf itunes_$now.tar.gz ~/Music/
tar cvzf pictures_$now.tar.gz ~/Pictures/


This is one of many backups, including TimeMachine, Synology NAS and SuperDuper. One can never have TOO many backups ;-)

My script calculates the current date/time and appends it to the filename: -

now=$(date +"%d_%m_%Y" +"_" +"%h:%m")

For some reason, that's stopped working recently - not sure precisely when but ...

This is what I now see: -

date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

A quick Google search later ( Adding date and time to file name ), I've changed the script to this: -

now=`date +%d-%m-%Y-%H-%M-%S`

and it works.

This is what I now get: -

notes_26-09-2014-15-56-38.tar.gz
docs_26-09-2014-15-56-38.tar.gz


etc.

No comments:

Note to self - use kubectl to query images in a pod or deployment

In both cases, we use JSON ... For a deployment, we can do this: - kubectl get deployment foobar --namespace snafu --output jsonpath="{...