sinisterporpoise: (Default)
2017-11-11 12:15 pm

BASH Script for backiing up all files iand directories in the home directory

This works on Linux, Unix and Mac OS X orlater, which I just checkeddoes have cron and the /etc/cronta file. It will create incremental backups.  For Mac users, this can be a way to add additional backups to Time Machine.

To schedule it regularly, you add the favorite line to the /etc/crontab file.   (I use Nano in Linux.)

02     00    *         *        *   /<path to dir>/bakup.sh

To make the script executable run the following commaind

chmod +x backup.sh


Now for the script:

#!/bin/bash
 
 
cat << here
 
-----------------------------------------------------------------------------
 
Sinister Porpoise Computing Backup Script
Test script for creating multiple
backup files.
 
Lara Landis
11/10/2017
Personal Bash Script
 
----------------------------------------------------------------------------
here
 
echo "Now creating backup files..."
 
x=1
y=1 
 
if -e [[ "backup.tar.gz" ]]; then
    x=1
    while (x=1)
    do
if -e [[ "backup" +y +".tar.gz" ]]; then
    x=1
    y=y+1
else 
  tar -czvf "backup" + y + ".tar.gz" /home
  x=0
fi
    done
else 
tar -cvzf "backuptar.gz" /home
fi;


There you go. It's just a simple script.