Miscellaneous

These are miscellaneous projects that are small enough to not warrant their own dedicated page.

Backup of smb1 ZFS datasets #Top

The following commands are to be run on ssds9

Attach tank-backup-a to the virtual machine:

virsh attach-disk kvm_smb1 /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJPLP6X vde --serial 68UW8N0_VKJNK77X --sourcetype block --cache none

The following commands are to be run on smb1

Import the backup tank and make a current set of snapshots:

zpool import tank-backup-a
zfs list -o name -Hr tank | xargs -IXXX -n1 zfs snapshot XXX@backup-time-$(date +'%Y%m%d')
zfs list -t snapshot | grep tank-backup-a #Get old backup timestamp names.

Transfer the snapshots to the backup disk:

zfs send -i tank/ssftp@backup-time-20180630 tank/ssftp@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-a/ssftp"
zfs send -i tank/applications@backup-time-20180630 tank/applications@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-a/applications"
zfs send -i tank/backups@backup-time-20180630 tank/backups@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-a/backups"
zfs send -i tank/multimedia@backup-time-20180630 tank/multimedia@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-a/multimedia"
zfs send -i tank/music@backup-time-20180630 tank/music@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-a/music"
zfs send -i tank/shared@backup-time-20180630 tank/shared@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-a/shared"

Export the backup tank:

zpool export tank-backup-a

The following commands are to be run on ssds9

Remove the backup disk from the virtual machine, power down the disk, and remove it from the kernel:

virsh detach-disk kvm_smb1 /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJPLP6X
hdparm -C /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJPLP6X
hdparm -Y /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJPLP6X
hdparm -C /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJPLP6X
echo 1 > /sys/block/$(basename $(realpath /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJPLP6X))/device/delete
systemctl restart smartd

Remove the backup disk.

tank-backup-b

The following commands are to be run on ssds9

Attach tank-backup-a to the virtual machine:

virsh attach-disk kvm_smb1 /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJNK77X vde --serial 68UW8N0_VKJNK77X --sourcetype block --cache none

The following commands are to be run on smb1

Import the backup tank and make a current set of snapshots:

zpool import tank-backup-b
zfs list -o name -Hr tank | xargs -IXXX -n1 zfs snapshot XXX@backup-time-$(date +'%Y%m%d')
zfs list -t snapshot | awk '/tank-backup-b/ {print $1}' # Get last backup date tank-backup-b/ssftp@backup-time-20180507 = 20180630

Transfer the snapshots to the backup disk:

zfs send -i tank/ssftp@backup-time-20180630 tank/ssftp@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-b/ssftp"
zfs send -i tank/shared@backup-time-20180630 tank/shared@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-b/shared"
zfs send -i tank/applications@backup-time-20180630 tank/applications@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-b/applications"
zfs send -i tank/backups@backup-time-20180507 tank/backups@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-b/backups"
zfs send -i tank/music@backup-time-20180630 tank/music@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-b/music"
zfs send -i tank/multimedia@backup-time-20180630 tank/multimedia@backup-time-$(date +'%Y%m%d') | pv | zfs receive "tank-backup-b/multimedia"

Export the backup tank:

zpool export tank-backup-b

The following commands are to be run on ssds9

Remove the backup disk from the virtual machine, power down the disk, and remove it from the kernel:

virsh detach-disk kvm_smb1 /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJNK77X
hdparm -C /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJNK77X
hdparm -Y /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJNK77X
hdparm -C /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJNK77X
echo 1 > /sys/block/$(basename $(realpath /dev/disk/by-id/ata-WDC_WD80EFZX-68UW8N0_VKJNK77X))/device/delete
systemctl restart smartd

Remove the backup disk.

buildhosts for Ubiquiti USG#Top

This script was written for the Ubiquiti USG. This script downloads various anti-ad hosts files, merges, sorts, and uniques, then installs a new /etc/hosts file for blocking advertisements and tracking.

Installation

Download buildhosts-unifi.sh and make it executable:

curl 'http://matthewheadlee.com/projects/miscellaneous/buildhosts-unifi.sh' > /usr/local/sbin/buildhosts-unifi.sh
chmod 700 /usr/local/sbin/buildhosts-unifi.sh

Run buildhosts-unifi.sh once to get the initial hosts file in-place:

buildhosts-unifi.sh

Create a new cron job to run buildhosts-unifi.sh once a week:

vi /etc/cron.d/buildhosts
# Run buildhosts every Thursday at 4:44AM
44 4 * * 4 root /usr/local/sbin/buildhosts-unifi.sh

Force Ubiquiti USG to use DNS servers in listed order#Top

The dnsmasq service running on a Ubiquiti USG uses the nameservers listed in /etc/resolv.conf in a round-robin fashion. WHen using split views on an internal nameserver, causes the USG to sometimes resolve the internal address and other times the external address.

echo strict-order > /etc/dnsmasq.d/strict-order.conf
service dnsmasq restart

buildhosts for DD-WRT#Top

This script was written for routers running DD-WRT. This script gets various anti-ad hosts files, merges, sorts, and uniques, then installs.

Download

Supercharger Parser v2#Top

This script grabs the locations of all Tesla chargers, including Superchargers and private chargers from teslamotors.com

Download

Supercharger Parser (Dead)#Top

No longer works, Tesla took down their list of webpages

This script grabs all of the supercharger pages from teslamotors.com and parses them for the GPS coordinates. It will do a Google Maps lookup if it cannot directly find the coordinates on the page. Currently the script is unable to lookup Chinese superchargers.

Download

Copyright © 2013 Matthew Headlee

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Questions or Feedback? #Top

Contact me