Chez ouam

/home/jmfrouin

View on GitHub
20 January 2013

Créer une archive tbz2 d'un répertoire

by Jean-Michel Frouin

Un script qui me permet de créer une archive tbz2 d'un répertoire.
Il prend un argument (ou pas, dans ce cas c'est le nom du répertoire courant) et sort : timestamp_argument.tbz2
Exemple :

~/toto# ./backup.sh
-> 2012_06_08-09_05_12-toto.tbz2
~/toto# ./backup.sh titi
-> 2012_06_08-09_05_12-titi.tbz2

Il me permet d'archiver des trucs ponctuellement, le timestamp en tete, permettant un tri aisé !

# History
# 0.02 : [2012/04/02] Add ability to call without argument, so use basename(pwd) instead
# 0.01 : Initial version

#!/bin/bash

EXPECTED_ARGS=1

timestamp=`date +%Y_%m_%d-%H_%M_%S`
dir_name=`pwd`;
archive_name=`basename $dir_name`

#echo "dir_name : $dir_name"
#echo "archive_name: $archive_name"
#echo "Timestamp used : $timestamp"

if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Will compress as $timestamp-$archive_name.tbz2"
  tar jcvf $timestamp-$archive_name.tbz2 * .git* --exclude=build --exclude=b
else
  echo "Will compress as $timestamp-$1.tbz2"
  tar jcvf $timestamp-$1.tbz2 * .git* --exclude=build --exclude=b
fi

Lien vers le script complet backup.sh.

tags: