Auto .tar a directory


Go to solution Solved by CS01-HS,

Recommended Posts

I have a network share where, every week, my Windows PC will perform a backup and store all the files in an Unraid network Share.  For various reasons, once my windows pc backup completes, I'd like to see if I can automatically .tar the contents of this directory.  I am also fine if it deletes the original data and curious to see if there would be a way to delete the .tar's after like 2 weeks or so (no more than 2 stored).  Is there an unraid feature, docker, code that can do something like this?

 

TIA!

Link to comment
  • Solution

If Windows backs up on the same day every week you could add a user script to unRAID that runs later or the next day.

I just wrote one similar for another device.

 

You may have to tweak it slightly for unraid/your use case. Carefully test it because it calls rm and you don't want to accidentally wipe your array (or at least comment out the rm line until you're sure it works.)

 

#!/bin/bash

#
# Backup critical files
#

## Options

# Number of backups to keep
NUM_TO_KEEP=6
# directory to be backed up
BACKUP_SOURCE="/mnt/hdd/share/unraid"
# directory to store backups
BACKUP_DEST="/mnt/hdd/share/backup"

# Begin backup
dest_file="${BACKUP_DEST}/unraid-$(date '+%Y-%m-%d')"
echo "Archiving critical files to: ${dest_file}.tar.gz"

tar -czf ${dest_file}.tar.gz ${BACKUP_SOURCE}
if [[ $? != 0 ]]; then
    # Alert
    echo "Critical Backup Archiving FAILED"
    exit 1
fi

# make it readable by all
chmod a+r ${dest_file}.tar.gz

# Clear out all but X most recent
(cd ${BACKUP_DEST}/ && rm `ls -t *.tar.gz | awk "NR>$NUM_TO_KEEP"`) 2>/dev/null

# Alert succes
echo "Critical Backup Archiving Completed"
exit 0

 

  • Thanks 1
Link to comment
56 minutes ago, CS01-HS said:

If Windows backs up on the same day every week you could add a user script to unRAID that runs later or the next day.

I just wrote one similar for another device.

 

You may have to tweak it slightly for unraid/your use case. Carefully test it because it calls rm and you don't want to accidentally wipe your array (or at least comment out the rm line until you're sure it works.)

 

#!/bin/bash

#
# Backup critical files
#

## Options

# Number of backups to keep
NUM_TO_KEEP=6
# directory to be backed up
BACKUP_SOURCE="/mnt/hdd/share/unraid"
# directory to store backups
BACKUP_DEST="/mnt/hdd/share/backup"

# Begin backup
dest_file="${BACKUP_DEST}/unraid-$(date '+%Y-%m-%d')"
echo "Archiving critical files to: ${dest_file}.tar.gz"

tar -czf ${dest_file}.tar.gz ${BACKUP_SOURCE}
if [[ $? != 0 ]]; then
    # Alert
    echo "Critical Backup Archiving FAILED"
    exit 1
fi

# make it readable by all
chmod a+r ${dest_file}.tar.gz

# Clear out all but X most recent
(cd ${BACKUP_DEST}/ && rm `ls -t *.tar.gz | awk "NR>$NUM_TO_KEEP"`) 2>/dev/null

# Alert succes
echo "Critical Backup Archiving Completed"
exit 0

 

Thanks I'll have to look at this.  Your statement is exactly what I need.  My issue is Crashplan won't store windows backups because it's excluded file type so i need to .tar it so it can be "included".  haha.  I just need to digest the script as I am a "newbie" when it comes to this.  

Link to comment

You can even include unraid notifications (in addition to the "echo" printouts.)

 

Notices ("normal") appear in green:

/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Backup Critical Files" -d "Backup complete" -i "normal"

 

and alerts in red:

/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Error" -s "Backup Critical Files" -d "Backup error" -i "alert"

 

Link to comment
5 minutes ago, CS01-HS said:

You can even include unraid notifications (in addition to the "echo" printouts.)

 

Notices ("normal") appear in green:

/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Backup Critical Files" -d "Backup complete" -i "normal"

 

and alerts in red:

/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Error" -s "Backup Critical Files" -d "Backup error" -i "alert"

 

Haha i wish i had your brains.  Thanks for this.  I am still studying the script and trying to understand.  Appreciate your help!

  • Haha 1
Link to comment
  • 5 months later...
On 8/13/2021 at 2:11 PM, CS01-HS said:
[ $? != 0 ]]; then
    # Alert
    echo "Critical Ba

 

On 8/13/2021 at 2:11 PM, CS01-HS said:

If Windows backs up on the same day every week you could add a user script to unRAID that runs later or the next day.

I just wrote one similar for another device.

 

You may have to tweak it slightly for unraid/your use case. Carefully test it because it calls rm and you don't want to accidentally wipe your array (or at least comment out the rm line until you're sure it works.)

 

#!/bin/bash

#
# Backup critical files
#

## Options

# Number of backups to keep
NUM_TO_KEEP=6
# directory to be backed up
BACKUP_SOURCE="/mnt/hdd/share/unraid"
# directory to store backups
BACKUP_DEST="/mnt/hdd/share/backup"

# Begin backup
dest_file="${BACKUP_DEST}/unraid-$(date '+%Y-%m-%d')"
echo "Archiving critical files to: ${dest_file}.tar.gz"

tar -czf ${dest_file}.tar.gz ${BACKUP_SOURCE}
if [[ $? != 0 ]]; then
    # Alert
    echo "Critical Backup Archiving FAILED"
    exit 1
fi

# make it readable by all
chmod a+r ${dest_file}.tar.gz

# Clear out all but X most recent
(cd ${BACKUP_DEST}/ && rm `ls -t *.tar.gz | awk "NR>$NUM_TO_KEEP"`) 2>/dev/null

# Alert succes
echo "Critical Backup Archiving Completed"
exit 0

 

Question on this and sorry for my delay, I got busy and didn't get a chance to fully explore.

 

So I assume you run this in the "Console" of Unraid to make it work.  And based on the backup settings, I assume it'll continue to run indefinitely.  How do you end this?  How do you modify this?  

 

Also, on the echo commands, that's the message displaying Successful or Failed -- does that come through as an Unraid notification?  I've familiarized myself with the script itself; however, just a little confused on execution since I am so used to Dockers/Apps.  


Thanks!

Link to comment
4 hours ago, Hawkins12 said:

And based on the backup settings, I assume it'll continue to run indefinitely.  How do you end this?

 

It runs once and exits.

 

4 hours ago, Hawkins12 said:

So I assume you run this in the "Console" of Unraid to make it work.

 

I run it on a different system. On unraid you'd add it as a User Script and set it to run weekly or daily.

 

4 hours ago, Hawkins12 said:

Also, on the echo commands, that's the message displaying Successful or Failed -- does that come through as an Unraid notification?

 

No it doesn't. For that you'd use the commands I mentioned above, either notice or error:

 

On 8/13/2021 at 3:28 PM, CS01-HS said:

You can even include unraid notifications (in addition to the "echo" printouts.)

 

Notices ("normal") appear in green:

/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Backup Critical Files" -d "Backup complete" -i "normal"

 

and alerts in red:

/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Error" -s "Backup Critical Files" -d "Backup error" -i "alert"

 

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.