Skip to content

Instantly share code, notes, and snippets.

@theand
Last active December 11, 2015 06:58
Show Gist options
  • Save theand/4562709 to your computer and use it in GitHub Desktop.
Save theand/4562709 to your computer and use it in GitHub Desktop.
#BASH full backup script for entire account
#!/bin/sh
prefix="home"
home_root="/home/"
backup_root="/backup/home_backup"
dir_name="$(date +%y%m%d)"
if [ ! -d $home_root ] ; then
echo "please type the home path"
fi
if [ ! -d $backup_root ] ; then
echo "create home backup folder.."
echo "mkdir -p $backup_root "
mkdir -p $backup_root
fi
if [ -d "$backup_root/$prefix.$dir_name" ]; then
echo "directory is existing",l
rm -rf "$backup_root/$prefix.$dir_name"
exit
else
echo "make directory.. "
mkdir "$backup_root/$prefix.$dir_name"
fi
for home_name in $(ls $home_root)
do
if [ -d "$home_root/$home_name" ] ; then
echo "$home_name home backuping..."
tar zcfp $backup_root/$prefix.$dir_name/$home_name.home.tar.gz $home_root/$home_name
fi
done
let "i = 0"
for dname in $(ls -t $backup_root)
do
let " i = i + 1"
if [ $i -ge "12" ]; then
if [ -d "$backup_root/$dname" ]; then
echo "Deleteing old archive"
rm -rf $backup_root/$dname
fi
fi
done
rm -f $backup_root/latest_home_backup
ln -s $backup_root/$prefix.$dir_name $backup_root/latest_home_backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment