- Configure
/tmp
as perfstab
, adjustsize
if needed - Copy
xdg-cache.service
to/etc/systemd/user/xdg-cache.service
- Copy
xdg-cache.sh
to/usr/local/bin/xdg-cache.sh
and thenchmod +x /usr/local/bin/xdg-cache.sh
- Run
systemctl --user enable xdg-cache.service
as the user that needs this service
Offloading XDG cache home to tmpfs
[Unit] | |
Description=Synchronises XDG cache between disk and tmpfs for %u | |
Before=default.target | |
[Service] | |
Type=oneshot | |
RemainAfterExit=true | |
ExecStart=/usr/local/bin/xdg-cache.sh ram | |
ExecStop=/usr/local/bin/xdg-cache.sh | |
StandardOutput=journal | |
StandardError=journal | |
TimeoutStopSec=1m | |
[Install] | |
WantedBy=default.target |
#!/usr/bin/env bash | |
PERSIST_DIR="$HOME/.cache" | |
TMP_DIR="/tmp/$USER/.cache" | |
if [[ "$1" == "ram" ]]; then | |
# to ram | |
if [ -d "$PERSIST_DIR" ]; then | |
#TIME='%C %Us user %Ss system %es total' time rsync -aq "$PERSIST_DIR/" "$TMP_DIR" | |
mkdir -p "$TMP_DIR" "$TMP_DIR-upper" | |
TIME='%C %Us user %Ss system %es total' time unionfs \ | |
-o rw,async,exec,suid,dev,nonempty,default_permissions,allow_other \ | |
-o use_ino,cow,statfs_omit_ro,hide_meta_files,max_files=65536 \ | |
"$TMP_DIR-upper=RW:$PERSIST_DIR=RO" "$TMP_DIR" | |
fi | |
elif [ -d "$TMP_DIR" ]; then | |
# to disk | |
TIME='%C %Us user %Ss system %es total' time rsync -ai --delete --delete-excluded --ignore-missing-args \ | |
--exclude='/google-chrome' \ | |
--exclude='/yay/*/' \ | |
--exclude='/pip' \ | |
--exclude='/kioexec' \ | |
--exclude='/wine' \ | |
--exclude='/go-build' \ | |
--exclude='/rclone' \ | |
--exclude='/spotify' \ | |
--exclude='/.nv' \ | |
"$TMP_DIR/" "$PERSIST_DIR" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment