Created
March 16, 2019 18:25
-
-
Save AstraLuma/624b499d213e607617187fee6a190ed1 to your computer and use it in GitHub Desktop.
Automatic Phone Backup (via udev and systemd)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACTION=="add", ENV{ID_SERIAL}=="*?", RUN+="/home/astraluma/udev-handler" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -ex | |
cd /home/astraluma/suraya | |
git annex unlock sdcard | |
adb pull -a /sdcard | |
git annex add sdcard | |
git annex sync --content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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