<html>
<head>
<meta name="generator" content="text2mime-markdown0.1">
<style>
code { font-family: 'Andale Mono', 'Lucida Console', 'Bitstream Vera Sans Mono', 'Courier New', monospace; }
pre { border-left: 20px solid #ddd; margin-left: 10px; padding-left: 5px; }
</style>
</head>
<body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title></title>
<style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<p>Utility <code>rsync</code> is a versatile tool for creating backups. A simple script which back-up dir1 to dir2 is following. It can also be found <a href="
http://dilawar.github.com/Scripts/backup.sh">here</a>.</p>
<pre><code> #!/bin/bash
# Original script :
https://wiki.archlinux.org/index.php/Full_System_Backup_with_rsync
# Modified by : Dilawar Singh &
lt;dila...@ncbs.res.in>
if [ $# -lt 2 ]; then
echo "No source and destination defined. Usage: $0 source destination" >&2
exit 1
elif [ $# -gt 2 ]; then
echo "Too many arguments. Usage: $0 source destination" >&2
exit 1
elif [ ! -d "$1" ]; then
echo "Invalid path: $1" >&2
exit 1
if [ ! -d "$1" ]; then
echo "Invalid path: $2" >&2
exit 1
fi
elif [ ! -w "$2" ]; then
echo "Directory not writable: $2" >&2
exit 1
fi
# Enable it if you are backing up in /media mount point.
#case "$2" in
# "/mnt") ;;
# "/mnt/"*) ;;
# "/media") ;;
# "/media/"*) ;;
# *) echo "Destination not allowed." >&2
# exit 1
# ;;
#esac
START=$(date +%s)
rsync -azv --progress $1 $2
FINISH=$(date +%s)
echo "total time: $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds"
touch $2/"Backup from $(date '+%A, %d %B %Y, %T')"
notify-send "Done backing up $1 to $2"</code></pre>
<p>Let's name this script <code>backup.sh</code> and make it executable (chmod +x backup.sh). Save it somewhere on system $PATH (e.g. /usr/local/bin). From command line:</p>
<pre><code> $ backup.sh /home/dilawar/Work /home/dilawar/Bhandar/Backup</code></pre>
<p>Usually one needs to repeatedly run this command every two hours or so to create backup. One can use <code>crontab</code> to automate this task. For example, if I want to run this script every two hours every-day. I do the following in terminal.</p>
<pre><code> $ crontab -e</code></pre>
<p>This will open an editor, write/append the following line to the opened file and close it.</p>
<pre><code> 0 0-23/2 * * * /usr/local/bin/backup.sh /home/dilawar/Work /home/dilawar/Bhandar/Backup</code></pre>
<p>There you go. Every two hours, you will see a small notification on the right-top corner of your screen that backup was successful.</p>
<p>NOTE: When copying using rsync, be careful about ending paths with <code>/</code>. If a path is ended with <code>/</code> e.g. <code>a/</code> it means copy everything under a, while <code>a</code> means copy directory a. Effectively, you don't get <code>a</code> in backup in the former (only its subdirectories).</p>
<pre><code> Dilawar</code></pre>
</body>
</html>
</body></html>