Creating backups with tar.gz and rsync

Killbots2012 asked:

I’m trying to use this bash script to create and send the tar.gz file to my backup server, some reason it doesn’t seem to copy it, is there a better solution to what I’m trying to do?

I’d rather have it compressed before I send it over the network

#!/bin/bash
####################################
#
# Backup to NFS mount script.
#
####################################

# What to backup. 
backup_files="/home/amp/.ampdata/instances/Towny/"

# Where to backup to.
dest="/home/amp/Backups"

# Create archive filename.
day=$(date +%A)
time=$(date +%H-%M)
file=$(file)
archive_file="$file-$day-$time.tgz"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
rsync $archive_file [email protected]:~/backup
# Print end status message.
echo
echo "Backup finished"
date

My answer:


Everywhere in your script you refer to $dest/$archive_file as the file you wish to create and copy, except in the rsync command that is supposed to copy it to the other host. Fix the call to rsync and try again.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.