I rearranged my server which means rearranging the backup automation scripts. I now have 2 backup drives that are 6TB and the media storage drive is 10TB, so I want to divide the 15 subvolumes across the 2 backup drives. Basically, I'm left with source, backup1, and backup2 and I want subvolumes 1-15 on different backups drives.
My previous script didn't work this way so I began anew. The first riddle was "Can I have one script that successfully divides the subvolumes between the two backup devices?" I'm not so concerned with current sizes of the subvolume because they grow and shrink as needed but I wanted to use all the capacity I have available.
Here's what I came up with. I removed everything but the parts that pertain to this post. I would like comments if there's a better way to do it:
"set" = all the subvolume names, "set1" = those I want to go to backup1, any missing from set1 are sent to backup2.
It's my first time using an array variable this way. Works like I want and amazingly short. I wanted to avoid repetitive code or dual scripts. If I decide later to re-arrange the backups or add more subvolumes I only have to add or subtract from the "set" and "set1" arrays.
It occurred to me that I could have the "set" array built from a simple "ls" command. Then any newly appearing subvolumes would be automatically added to the process and sent to backup2.
Or I could even adjust the target backup location by using a trailing number in the subvolume name - like a 1 or 2 at the end of the name to set the backup location or read the list from a text file instead of in the script itself, but I doubt I'll be changing this around much.
My previous script didn't work this way so I began anew. The first riddle was "Can I have one script that successfully divides the subvolumes between the two backup devices?" I'm not so concerned with current sizes of the subvolume because they grow and shrink as needed but I wanted to use all the capacity I have available.
Here's what I came up with. I removed everything but the parts that pertain to this post. I would like comments if there's a better way to do it:
Code:
declare -a set=(@Audio @Backups @Documents @Downloads @Home_Movies @Incoming @Movies @Music @Music_Videos @Pictures @Projects @TV_Shows @Videos @WWW) declare -a set1=(@Audio @Backups @Documents @Downloads @Home_Movies @Incoming @Music @Music_Videos @Pictures @Projects @Videos @WWW) for subvol in ${set[@]} ; do if [[ ${set1[@]} = *"$subvol"* ]]; then backup_mount=backup1_mount ; else backup_mount=backup2_mount ; fi
It's my first time using an array variable this way. Works like I want and amazingly short. I wanted to avoid repetitive code or dual scripts. If I decide later to re-arrange the backups or add more subvolumes I only have to add or subtract from the "set" and "set1" arrays.
It occurred to me that I could have the "set" array built from a simple "ls" command. Then any newly appearing subvolumes would be automatically added to the process and sent to backup2.
Or I could even adjust the target backup location by using a trailing number in the subvolume name - like a 1 or 2 at the end of the name to set the backup location or read the list from a text file instead of in the script itself, but I doubt I'll be changing this around much.
Comment