Backup a folder

I usually keep this script in the
“/usr/bin/archive” file and make it executable.

#!/bin/bash

FOLDER=$1
NOW=$(date +"%Y-%m-%d")

OUTPUT="tar -cjf $FOLDER-$NOW.tar.bz $FOLDER"
echo $OUTPUT
$OUTPUT

Usage:

$ archive folder_name

Will create a file “folder_name-2010-07-18.tar.bz” in the current directory. Then you can rm -rf the folder and copy the archive to your archived location.

This goes well with “/usr/bin/archive_all”

#!/bin/bash

for file in *;
do
if [ -d "$file" ]; then
archive "$file";
fi

done;

This will create archives of all the subdirectories in the current directory. This is good for archiving old projects that don’t need to be uncompressed anymore.

Leave a Comment