Spyke
linux·Linuxbysartaj

[Solved] move files older than 30 days from one computer to another using rsync

I have a laptop and a phone in which termux is installed. I want to move files from my phone to my computer using rsync if all files are older than 30 days. I think I should use find command with -exec rsync.

find . -mtime +30 -exec rsync something 

but the problem is my phone's IP address is always changing so how do I transfer file? I have to run this script in my laptop

solution

i wrote a script which move files and runs in my laptop

  1. i can't use hostname because I am on android 9 and don't want to install anything else.
  2. most of the time I am offline so using any internet service is not a good idea ( my devices are connected in themselves )

here is my script

#!/usr/bin/bash

#checking if script not already running and exit if already running
[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :

set -e

TARGET_MAC="d2:1c:3c:3d:6a:a7"
RSYNC_LOG="$HOME/log/rsync_log.txt"  # Rclone log file


function get_ip() {
  # need to edit sudoers file to run 	sudo nmap -sn 192.168.43.0/24 without password
  # Allow members of group sudo to execute any command
  # %sudo	ALL=(ALL:ALL) ALL
  # 'username' ALL=(ALL) NOPASSWD: /usr/bin/nmap -sn 192.168.43.0/24


	sudo nmap -sn 192.168.43.0/24 | grep --before-context=3 -i "$TARGET_MAC" | tail -n 3 | head -n 1 | awk '{ print $6 }' | sed 's/[()]//g'; }


# run command only if wifi is connected
if echo $(nmcli general status) | grep -q -w "connected" ; then

  # for ssh to work in a changing IP address, a configuration line has to be enabled so that it does not ask for yes/no while connecting to a changed ip address
	TARGET_IP=$(get_ip)
  ssh -p 8022  "$TARGET_IP" 'find /data/data/com.termux/files/home/storage/shared/Pictures/ -mtime +30  -type d,f -printf %P\\0' | rsync --append --update --times --atimes --mkpath --verbose --human-readable --remove-source-files --log-file="$HOME/log/synced.log" --exclude='.dtrash' --files-from=- --from0  -e "ssh -p 8022" "$TARGET_IP":/data/data/com.termux/files/home/storage/shared/Pictures/ $HOME/Pictures
View original on lemmy.world
lemm.ee

DNS was invented in 1985 to solve this problem.

You could also run it from the phone.

19
catloafreply
lemm.ee

So you'd rather reinvent TCP/IP from scratch?

4
lemm.ee

VPN.. This is a specific problem that VPNs were created to solve.

On your Wireguard network (or whichever), note your vLAN IPs, and configure rclone/rsync with them like normal. Ensure you're connected to Wireguard and then run your command;

❯ fd --change-older-than 30days -X rclone sync phone:my/path/here pc:destination/path/here

Using a VPN ensures that regardless of WiFi/Cellular connections you'll still be able to transfer at home, or remotely. Using methods like hostnames only work locally.

6
Xanzareply

Seems dubious, and will only work locally..

1

i dont want to install another app and tweak battey saver setting, auto start managent etc. termux is already set up

3

You reached the end