Overclock.net banner

1 - 15 of 15 Posts

·
Linux > All
Joined
·
1,680 Posts
Discussion Starter · #1 ·
I have a pair of usb drives sole purpose is current backup every 30 minutes. Is this script as optimum as it gets or can I shrink it further. It started out as 2 scripts so it's already half of what it was before just looking to learn and optimize further..
Code:

Code:
#!/bin/bash
# myautomount
# auto mount backup drives
# last edit : 2014/4/3 - 4:20 pm
# tadaen sylvermane

##### begin script #####

backup()
{
  if ! mountpoint -q $2 ; then
    mount $2 && rsync -au --delete --include-from="${1}.include" --exclude="/*" $1 $2
  else
    rsync -au --delete --include-from="${1}.include" --exclude="/*" $1 $2
  fi    
}

## while loop ##

while true
do
  backup /media/data/ /media/backups/fdd
  backup /media/data/ /media/backups/hdd
  sleep 1200
done

##### end script #####
 

·
Registered
Joined
·
1,526 Posts
Quote:
Originally Posted by tompsonn View Post

I guess you could run it on a cron and get rid of the while loop
biggrin.gif
This is what I would do. Otherwise, it's a pretty basic script. There isn't really anything to optimize.

If you're looking to expand on it, I would add in some error handling and logging. Double pipes (||) do the opposite of the double ampersand (&&), so you can use that functionality to catch errors (exit code greater than 0) and run another function. That function I would have write to a log file and maybe even send an email if you want to get really fancy.
 

·
Senioritis Member
Joined
·
8,360 Posts

·
Linux > All
Joined
·
1,680 Posts
Discussion Starter · #6 ·
Quote:
Originally Posted by Ferrari8608 View Post

The OP is using Linux Mint.
This. Plus this is more of me learning and building as I learn than anything necessary. I'm sure I could find an app that would do it all for me.
 

·
Senioritis Member
Joined
·
8,360 Posts
Quote:
Originally Posted by Ferrari8608 View Post

The OP is using Linux Mint.
Oopsie! I missed that. Sorry!
 

·
Premium Member
Joined
·
10,773 Posts
Quote:
Originally Posted by Tadaen Sylvermane View Post

This. Plus this is more of me learning and building as I learn than anything necessary. I'm sure I could find an app that would do it all for me.
That might be harder than you think. I sifted through a few Linux backup applications and gave up and went back to rsync... so stay where you are
tongue.gif
 

·
Linux > All
Joined
·
1,680 Posts
Discussion Starter · #9 ·
Quote:
Originally Posted by tompsonn View Post

That might be harder than you think. I sifted through a few Linux backup applications and gave up and went back to rsync... so stay where you are
tongue.gif
For once I'm ahead of the curve! Lol.

*EDIT* And I did change it from a function to just a single script, removing the while loop and have a pair of cron jobs running now. Not gonna mess with any error handling as I'm out and about with laptop regularly, don't want a bunch of emails or error logs just because the backup drives are at home. I will however look into it if only for the learning experience.
 

·
Premium Member
Joined
·
8,040 Posts
Quote:
Originally Posted by tompsonn View Post

That might be harder than you think. I sifted through a few Linux backup applications and gave up and went back to rsync... so stay where you are
tongue.gif
Did you try Backula? That's supposed to be quite good from what I've seen and read.

Personally though, I just use rsync too.
Quote:
Originally Posted by Tadaen Sylvermane View Post

For once I'm ahead of the curve! Lol.

*EDIT* And I did change it from a function to just a single script, removing the while loop and have a pair of cron jobs running now. Not gonna mess with any error handling as I'm out and about with laptop regularly, don't want a bunch of emails or error logs just because the backup drives are at home. I will however look into it if only for the learning experience.
easiest way to log would be to add:

Code:

Code:
set -vx
to the top of your script (but after #!/bin/bash). This is roughly equivalent of the old echo on in DOS, so all you now need to do is add a redirect in your crontab. eg.

Code:

Code:
0 0 * * * /path/to/script 2>&1 > /var/log/backup
 

·
Registered
Joined
·
753 Posts
I use BackupPC, which uses rsync. It works great, and even finds out the best time to do backups based on your usage and uptime.
 

·
Registered
Joined
·
2,039 Posts
Quote:
Originally Posted by tompsonn View Post

I did try Bacula. It needed too much crapula to set up
tongue.gif
yeah ,bacula sucks...., not very user intuitive...., took me like 4 hours to get my simple scsi lto2 drive to work with it.
 

·
Registered
Joined
·
560 Posts
So you are making 2 identical backups at 30 minute increments. What if you delete something accidentally, you will replicate that error twice to your backups. Take out the while loop and pass the usb device as a positional parameter to the script. Then set one cron entry as a 30 minute backup and the other as a daily using the same script but with different usb devices.
 

·
Linux > All
Joined
·
1,680 Posts
Discussion Starter · #15 ·
I don't have anything important to worry about losing. Absolutely nothing. I keep a mirror. I have a separate backup that I do manually every now and again. I'm mirroring only certain folders such as music, videos, and pictures.
 
1 - 15 of 15 Posts
Top