3

How can I skip backing up my "Downloads" folder?

here's my code:

#!/bin/bash

# Daily backup script

# Create some needed variable
day=$(date +%F)
Folder="/home/ME/"

File="/media/MediaTwo/Copy/UbuntuBackup/$day.tar.gz"

# Backup Server Configuration
tar cpzf $File $Folder

# Remove backup files older than 90 days
find $File* -mtime +90 -exec rm {} \;
Kevin
  • 2,684
  • 6
  • 35
  • 64
  • 1
    check it here, it may duplicate `http://stackoverflow.com/questions/984204/shell-command-to-tar-directory-excluding-certain-files-folders` – Haifeng Zhang Jun 02 '14 at 21:12

4 Answers4

5
tar cpzf $File --exclude=Downloads $Folder
R Sahu
  • 204,454
  • 14
  • 159
  • 270
2

The easiest way to exclude your Downloads folder is to add an option (i.e. --exclude) to the tar command.

I would suggest modifying line 12 of your code to read:

tar cpzf $File --exclude "${Folder}Downloads" $Folder

I think this should do what you're looking for.

BillyBBone
  • 3,144
  • 3
  • 23
  • 27
2

Use extended pattern matching:

shopt -s extglob; shopt -s dotglob
tar cpzf "$File" "$Folder"/!(Downloads)
konsolebox
  • 72,135
  • 12
  • 99
  • 105
1

I sugest this one for maximum speed on multi core machines :

tar -c --use-compress-program=pigz -f $File --exclude=Downloads $Folder
manuc66
  • 2,701
  • 29
  • 28