Backup directories with space in directory name
Jack McGee
jack at greendesk.net
Sat Dec 31 16:14:25 UTC 2016
On 12/30/2016 11:12 PM, Karl Auer wrote:
> On Fri, 2016-12-30 at 21:47 -0600, Jack McGee wrote:
>> I am trying to use this perl script to backup a directory, but it
>> fails with this error:
> You need to protect every expansion point with one set of quotes.
>
>> # What to backup.
>> backup_files="/mnt/ntfs-d/My Documents"
> That's good. That will keep the path safe *within this script*.
> However, the variable name is poor, since the value is not a list of
> files, the value is the name of a directory containing files to back
> up. Suggest something like "directory_to_back_up".
>
> BTW, if you ever want to put more than one directory name into that
> variable, you will need to do more work than described here.
>
> Regards, K.
>
Thanks all. It succesfully backed up the My Documents folder, but of
course, now I want to have it also backup
/usr/local, /var /etc /opt /home
anything else that I would need to restore if I wiped system? Any of
that I don't?
How should I tweak script further to allow that?
jmcgee at jmcgee-desktop:/usr/local/bin$ cat backupsystemrotate
#!/bin/bash
#set -e
####################################
#
# Backup to NFS mount script with
# grandfather-father-son rotation.
#
####################################
# What to backup.
backup_files="/mnt/ntfs-d/My Documents"
# Where to backup to.
dest="/mnt/media3/backups/desktop"
# Setup variables for the archive filename.
day=$(date +%A)
hostname=$(hostname -s)
# Find which week of the month 1-4 it is.
day_num=$(date +%d)
if (( $day_num <= 7 )); then
week_file="$hostname-week1.tgz"
elif (( $day_num > 7 && $day_num <= 14 )); then
week_file="$hostname-week2.tgz"
elif (( $day_num > 14 && $day_num <= 21 )); then
week_file="$hostname-week3.tgz"
elif (( $day_num > 21 && $day_num < 32 )); then
week_file="$hostname-week4.tgz"
fi
# Find if the Month is odd or even.
month_num=$(date +%m)
month=$(expr $month_num % 2)
if [ $month -eq 0 ]; then
month_file="$hostname-month2.tgz"
else
month_file="$hostname-month1.tgz"
fi
# Create archive filename.
if [ $day_num == 1 ]; then
archive_file=$month_file
elif [ $day != "Saturday" ]; then
archive_file="$hostname-$day.tgz"
else
archive_file=$week_file
fi
# 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"
# Print end status message.
echo
echo "Backup finished"
date
# Long listing of files in $dest to check file sizes.
ls -lh "$dest/"
More information about the ubuntu-users
mailing list