mirror of
https://github.com/Xevion/dotfiles.git
synced 2025-12-06 01:14:48 -06:00
viofo_backup: fixed indentation, always unmount after mounting properly
This commit is contained in:
@@ -6,11 +6,15 @@ use std/log
|
||||
# It is intended to be ran semi-rarely (every month or two), and is also a limited test of the Fish shell/scripting language.
|
||||
# It is intended to be cross-platform, but targets Ubuntu 22.04 LTS (with WSL2 support).
|
||||
|
||||
try {
|
||||
# Configuration details
|
||||
let host = "roman" # The host to backup to. This is defined in the ~/.ssh/config file.
|
||||
let host_path = "/mnt/user/media/backup/dashcam" # The path on the remote host to backup to.
|
||||
|
||||
# Global state tracking
|
||||
mut mounted = false # Track if we've mounted a drive
|
||||
mut letter = "" # Track the drive letter we're using
|
||||
|
||||
try {
|
||||
# Check for required commands
|
||||
let required_commands = ["rsync", "sudo", "mount", "umount", "cmd.exe", "ssh"]
|
||||
for cmd in $required_commands {
|
||||
@@ -70,7 +74,7 @@ if ($mountable | length) == 0 {
|
||||
|
||||
# Have the user choose a drive
|
||||
let selected_drive = $mountable | input list -d "DeviceID" "Select a drive to mount for backup"
|
||||
let letter = $selected_drive.DeviceId | str replace --regex ":$" "" | str downcase
|
||||
$letter = $selected_drive.DeviceId | str replace --regex ":$" "" | str downcase
|
||||
let win_drive_path = $"($letter | str upcase):"
|
||||
|
||||
# Check if already mounted
|
||||
@@ -78,6 +82,7 @@ log info "Checking if drive is already mounted..."
|
||||
let findmnt_check = findmnt -J --mountpoint /mnt/($letter) | complete
|
||||
if $findmnt_check.exit_code == 0 {
|
||||
log debug "Drive is already mounted"
|
||||
$mounted = true
|
||||
|
||||
# Check was successful, meaning something must be mounted there
|
||||
let mounts = $findmnt_check.stdout | from json
|
||||
@@ -106,7 +111,7 @@ if $findmnt_check.exit_code == 0 {
|
||||
|
||||
log info $"Mount Details: ($current_mount.options)"
|
||||
while true {
|
||||
let continue = input "Continue anyways? (y/n)"
|
||||
let continue = input "Continue anyways? [y/n]"
|
||||
if $continue == "y" {
|
||||
break
|
||||
} else if $continue == "n" {
|
||||
@@ -131,6 +136,7 @@ if $findmnt_check.exit_code == 0 {
|
||||
try {
|
||||
log debug "Mounting drive..."
|
||||
sudo mount -t drvfs ($win_drive_path) /mnt/($letter) -o uid=(id -u $env.USER),gid=(id -g $env.USER),metadata
|
||||
$mounted = true
|
||||
} catch { |err|
|
||||
log error $"Error: Could not mount drive: ($err.msg)"
|
||||
exit 1
|
||||
@@ -146,6 +152,7 @@ if $findmnt_check.exit_code == 0 {
|
||||
error "Failed to mount drive"
|
||||
}
|
||||
|
||||
try {
|
||||
# Test permissions & folder structure
|
||||
let expected_folders = [
|
||||
"DCIM",
|
||||
@@ -162,7 +169,6 @@ if $findmnt_check.exit_code == 0 {
|
||||
let status = test -d ($path) | complete
|
||||
if $status.exit_code != 0 {
|
||||
error $"Expected folder "($path)" does not exist."
|
||||
|
||||
} else {
|
||||
log debug $"Folder "($path)" exists"
|
||||
}
|
||||
@@ -200,21 +206,25 @@ if $findmnt_check.exit_code == 0 {
|
||||
}
|
||||
|
||||
log info "Sync complete."
|
||||
} catch {|err|
|
||||
log error $"Failed after mounting: ($err.msg)"
|
||||
}
|
||||
|
||||
# Unmount the drive
|
||||
log info "Unmounting drive..."
|
||||
try {
|
||||
sudo umount /mnt/($letter)
|
||||
sudo rmdir /mnt/($letter)
|
||||
|
||||
# TODO: Check if duplicate mounts exist
|
||||
log info "All backed up."
|
||||
$mounted = false
|
||||
} catch { |err|
|
||||
log error $"Could not unmount drive: ($err.msg)"
|
||||
exit 999
|
||||
}
|
||||
} catch { |err|
|
||||
log error $"Error: Could not unmount drive: ($err.msg)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
# TODO: Statistical analysis of file duration
|
||||
# On average, how far back do my recordings go? 2 months?
|
||||
# While the oldest video file could give an idea of how back I currently go, it would be better to use p99 average bitrate.
|
||||
|
||||
Reference in New Issue
Block a user