Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Created March 16, 2019 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AstraLuma/624b499d213e607617187fee6a190ed1 to your computer and use it in GitHub Desktop.
Save AstraLuma/624b499d213e607617187fee6a190ed1 to your computer and use it in GitHub Desktop.
Automatic Phone Backup (via udev and systemd)
ACTION=="add", ENV{ID_SERIAL}=="*?", RUN+="/home/astraluma/udev-handler"
#!/bin/sh
set -ex
cd /home/astraluma/suraya
git annex unlock sdcard
adb pull -a /sdcard
git annex add sdcard
git annex sync --content
#!/usr/bin/python3
import logging
import logging.handlers
logging.basicConfig(
handlers=[logging.handlers.SysLogHandler(address='/dev/log')],
format="%(name)s %(message)s",
level=0,
)
logger = logging.getLogger()
try:
import os
import sys
import subprocess
if os.environ['ACTION'] == 'add' and os.environ['ID_SERIAL'] == "Google_Pixel_2_XL_801KPXV1506706":
logger.info("Starting backup")
cmd = subprocess.run(
['systemd-run', '--uid=astraluma', '--no-ask-password', '/home/astraluma/backup'],
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
logger.debug("systemd-run (%i):\n%s", cmd.returncode, cmd.stdout.decode('ascii'))
except Exception as e:
logger.exception("Exception raised: %r", e)
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment