New Posts  All Forums:Forum Nav:

Backup script.

post #1 of 15
Thread Starter 
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..
Script Here (Click to show)
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 #####
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #2 of 15
I guess you could run it on a cron and get rid of the while loop biggrin.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #3 of 15
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.
post #4 of 15
I cheat and just use Macrium Reflect Free (Here is a good tutorial on how to use Macrium Reflect) to back up my OS/Programs and FreeFileSync to back up my data.
     
CPUMotherboardGraphicsRAM
i7-5930K Haswell-e Asus X99-E WS/USB 3.1 Visiontek Radeon 7870 2GB with 6 miniDisplayports G-Skill Ripjaws 64GB (8x8GB) DDR4 2133 
Hard DriveHard DriveCoolingOS
Samsung 850 EVO 4TB SSDs Samsung 950 Pro 512GB m.2 SSD boot drive Noctua NH-D15S Cpu cooler Win 7 Ultimate 
PowerCaseMouseMouse Pad
Corsair AX760 Scratch built. Currently under construction at ... Logitech M525 El Cheapo Allsop hard plastic 
CPUMotherboardGraphicsGraphics
i7-3930k ASUS P9X79 WS MSI R7850 Twin Frozr 2GD5/OC Radeon HD 7850 2GB... Monoprice 1x2 powered HDMI Splitter 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 32GB (8 x 4GB) 240-Pin DDR3 SDR... 128GB Samsung 840 Pro SSD 4TB Samsung 850 EVO SSD 4TB Samsung 850 EVO SSD 
Hard DriveHard DriveOptical DriveCooling
4TB Samsung 850 EVO SSD 4TB Samsung 850 EVO SSD LG 12X BD-ROM 16X DVD-ROM 48X CD-ROM SATA Inter... COOLER MASTER GeminII S524 120mm Long Life Slee... 
OSMonitorMonitorKeyboard
Windows 7 Ultimate 3 x Asus VG248QE Vizio VO320E 32" TV Logitech G510s 
PowerCaseMouseAudio
Corsair HX750W Antec Two Hundred v2 Logitech M525 with Unifying Receiving Corsair SP2500 2.1 Speakers 
AudioOtherOtherOther
ASUS Xonar Essence STX Virtual 7.1 Channels 24-... LSI 9211-8i HBA card HooToo® HT-CR001 3.5" PCI-E to USB 3.0 Multi-in... StarTech HSB220SAT25B 2 Drive 2.5in Trayless Ho... 
  hide details  
Reply
     
CPUMotherboardGraphicsRAM
i7-5930K Haswell-e Asus X99-E WS/USB 3.1 Visiontek Radeon 7870 2GB with 6 miniDisplayports G-Skill Ripjaws 64GB (8x8GB) DDR4 2133 
Hard DriveHard DriveCoolingOS
Samsung 850 EVO 4TB SSDs Samsung 950 Pro 512GB m.2 SSD boot drive Noctua NH-D15S Cpu cooler Win 7 Ultimate 
PowerCaseMouseMouse Pad
Corsair AX760 Scratch built. Currently under construction at ... Logitech M525 El Cheapo Allsop hard plastic 
CPUMotherboardGraphicsGraphics
i7-3930k ASUS P9X79 WS MSI R7850 Twin Frozr 2GD5/OC Radeon HD 7850 2GB... Monoprice 1x2 powered HDMI Splitter 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 32GB (8 x 4GB) 240-Pin DDR3 SDR... 128GB Samsung 840 Pro SSD 4TB Samsung 850 EVO SSD 4TB Samsung 850 EVO SSD 
Hard DriveHard DriveOptical DriveCooling
4TB Samsung 850 EVO SSD 4TB Samsung 850 EVO SSD LG 12X BD-ROM 16X DVD-ROM 48X CD-ROM SATA Inter... COOLER MASTER GeminII S524 120mm Long Life Slee... 
OSMonitorMonitorKeyboard
Windows 7 Ultimate 3 x Asus VG248QE Vizio VO320E 32" TV Logitech G510s 
PowerCaseMouseAudio
Corsair HX750W Antec Two Hundred v2 Logitech M525 with Unifying Receiving Corsair SP2500 2.1 Speakers 
AudioOtherOtherOther
ASUS Xonar Essence STX Virtual 7.1 Channels 24-... LSI 9211-8i HBA card HooToo® HT-CR001 3.5" PCI-E to USB 3.0 Multi-in... StarTech HSB220SAT25B 2 Drive 2.5in Trayless Ho... 
  hide details  
Reply
post #5 of 15
The OP is using Linux Mint.
post #6 of 15
Thread Starter 
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.
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #7 of 15
Quote:
Originally Posted by Ferrari8608 View Post

The OP is using Linux Mint.

Oopsie! I missed that. Sorry!
     
CPUMotherboardGraphicsRAM
i7-5930K Haswell-e Asus X99-E WS/USB 3.1 Visiontek Radeon 7870 2GB with 6 miniDisplayports G-Skill Ripjaws 64GB (8x8GB) DDR4 2133 
Hard DriveHard DriveCoolingOS
Samsung 850 EVO 4TB SSDs Samsung 950 Pro 512GB m.2 SSD boot drive Noctua NH-D15S Cpu cooler Win 7 Ultimate 
PowerCaseMouseMouse Pad
Corsair AX760 Scratch built. Currently under construction at ... Logitech M525 El Cheapo Allsop hard plastic 
CPUMotherboardGraphicsGraphics
i7-3930k ASUS P9X79 WS MSI R7850 Twin Frozr 2GD5/OC Radeon HD 7850 2GB... Monoprice 1x2 powered HDMI Splitter 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 32GB (8 x 4GB) 240-Pin DDR3 SDR... 128GB Samsung 840 Pro SSD 4TB Samsung 850 EVO SSD 4TB Samsung 850 EVO SSD 
Hard DriveHard DriveOptical DriveCooling
4TB Samsung 850 EVO SSD 4TB Samsung 850 EVO SSD LG 12X BD-ROM 16X DVD-ROM 48X CD-ROM SATA Inter... COOLER MASTER GeminII S524 120mm Long Life Slee... 
OSMonitorMonitorKeyboard
Windows 7 Ultimate 3 x Asus VG248QE Vizio VO320E 32" TV Logitech G510s 
PowerCaseMouseAudio
Corsair HX750W Antec Two Hundred v2 Logitech M525 with Unifying Receiving Corsair SP2500 2.1 Speakers 
AudioOtherOtherOther
ASUS Xonar Essence STX Virtual 7.1 Channels 24-... LSI 9211-8i HBA card HooToo® HT-CR001 3.5" PCI-E to USB 3.0 Multi-in... StarTech HSB220SAT25B 2 Drive 2.5in Trayless Ho... 
  hide details  
Reply
     
CPUMotherboardGraphicsRAM
i7-5930K Haswell-e Asus X99-E WS/USB 3.1 Visiontek Radeon 7870 2GB with 6 miniDisplayports G-Skill Ripjaws 64GB (8x8GB) DDR4 2133 
Hard DriveHard DriveCoolingOS
Samsung 850 EVO 4TB SSDs Samsung 950 Pro 512GB m.2 SSD boot drive Noctua NH-D15S Cpu cooler Win 7 Ultimate 
PowerCaseMouseMouse Pad
Corsair AX760 Scratch built. Currently under construction at ... Logitech M525 El Cheapo Allsop hard plastic 
CPUMotherboardGraphicsGraphics
i7-3930k ASUS P9X79 WS MSI R7850 Twin Frozr 2GD5/OC Radeon HD 7850 2GB... Monoprice 1x2 powered HDMI Splitter 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 32GB (8 x 4GB) 240-Pin DDR3 SDR... 128GB Samsung 840 Pro SSD 4TB Samsung 850 EVO SSD 4TB Samsung 850 EVO SSD 
Hard DriveHard DriveOptical DriveCooling
4TB Samsung 850 EVO SSD 4TB Samsung 850 EVO SSD LG 12X BD-ROM 16X DVD-ROM 48X CD-ROM SATA Inter... COOLER MASTER GeminII S524 120mm Long Life Slee... 
OSMonitorMonitorKeyboard
Windows 7 Ultimate 3 x Asus VG248QE Vizio VO320E 32" TV Logitech G510s 
PowerCaseMouseAudio
Corsair HX750W Antec Two Hundred v2 Logitech M525 with Unifying Receiving Corsair SP2500 2.1 Speakers 
AudioOtherOtherOther
ASUS Xonar Essence STX Virtual 7.1 Channels 24-... LSI 9211-8i HBA card HooToo® HT-CR001 3.5" PCI-E to USB 3.0 Multi-in... StarTech HSB220SAT25B 2 Drive 2.5in Trayless Ho... 
  hide details  
Reply
post #8 of 15
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
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #9 of 15
Thread Starter 
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.
Edited by Tadaen Sylvermane - 4/6/14 at 8:48am
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #10 of 15
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:
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:
0 0 * * * /path/to/script 2>&1 > /var/log/backup
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix