Use /mnt/borg-backups in place of /mnt/object_storage for Borg. Remove JuiceFS and Redis artifacts (tasks, templates, service configs) and delete borg-local-sync tooling. Update borg-backup service ReadWritePaths, remove Plex slow tvshows mount, add system sysctl performance tunings, and apply minor code and flake.lock updates.
92 lines
2.9 KiB
Python
Executable File
92 lines
2.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""Generate export commands for Borg environment variables."""
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
# Add the bin directory to the path
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
|
from helpers.functions import printfe
|
|
|
|
|
|
def get_borg_passphrase():
|
|
"""Get Borg passphrase from 1Password"""
|
|
try:
|
|
result = subprocess.run(
|
|
[
|
|
"op",
|
|
"item",
|
|
"get",
|
|
"Borg Backup",
|
|
"--vault=Dotfiles",
|
|
"--fields=password",
|
|
"--reveal",
|
|
],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
return result.stdout.strip()
|
|
except subprocess.CalledProcessError:
|
|
printfe("red", "Error: Failed to retrieve Borg passphrase from 1Password")
|
|
return None
|
|
|
|
|
|
def main():
|
|
"""Generate export commands for Borg environment variables"""
|
|
args = sys.argv[1:] if len(sys.argv) > 1 else []
|
|
|
|
# Get passphrase from 1Password
|
|
passphrase = get_borg_passphrase()
|
|
if not passphrase:
|
|
return 1
|
|
|
|
# Generate the export commands
|
|
exports = [
|
|
'export BORG_REPO="/mnt/borg-backups"',
|
|
f'export BORG_PASSPHRASE="{passphrase}"',
|
|
'export BORG_CACHE_DIR="/home/menno/.config/borg/cache"',
|
|
'export BORG_CONFIG_DIR="/home/menno/.config/borg/config"',
|
|
'export BORG_SECURITY_DIR="/home/menno/.config/borg/security"',
|
|
'export BORG_KEYS_DIR="/home/menno/.config/borg/keys"',
|
|
]
|
|
|
|
# Check if we're being eval'd (no arguments and stdout is a pipe)
|
|
if not args and not os.isatty(sys.stdout.fileno()):
|
|
# Just output the export commands for eval
|
|
for export_cmd in exports:
|
|
print(export_cmd)
|
|
return 0
|
|
|
|
# Print instructions and examples
|
|
printfe("cyan", "🔧 Borg Environment Setup")
|
|
print()
|
|
printfe("yellow", "Run the following command to setup your shell:")
|
|
print()
|
|
printfe("green", "eval $(dotf source)")
|
|
print()
|
|
printfe("red", "⚠️ Repository Permission Issue:")
|
|
printfe("white", "The Borg repository was created by root, so you need sudo:")
|
|
print()
|
|
printfe("green", "sudo -E borg list")
|
|
printfe("green", "sudo -E borg info")
|
|
print()
|
|
printfe("yellow", "Or copy and paste these exports:")
|
|
print()
|
|
# Output the export commands
|
|
for export_cmd in exports:
|
|
print(export_cmd)
|
|
print()
|
|
printfe("cyan", "📋 Borg commands (use with sudo -E):")
|
|
printfe("white", " sudo -E borg list # List all backups")
|
|
printfe("white", " sudo -E borg info # Repository info")
|
|
printfe("white", " sudo -E borg list ::archive-name # List files in backup")
|
|
printfe("white", " sudo -E borg mount . ~/borg-mount # Mount as filesystem")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|