Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rahaaatul/obsync
Easily sync your Obsidian vault between your desktop and mobile devices leveraging FTP for file transfer.
https://github.com/rahaaatul/obsync
android backup bash bash-script ftp ftp-client obsidian-md script termux windows
Last synced: 22 days ago
JSON representation
Easily sync your Obsidian vault between your desktop and mobile devices leveraging FTP for file transfer.
- Host: GitHub
- URL: https://github.com/rahaaatul/obsync
- Owner: rahaaatul
- License: mit
- Created: 2024-06-16T14:12:55.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-16T14:30:31.000Z (5 months ago)
- Last Synced: 2024-09-30T09:40:51.026Z (about 1 month ago)
- Topics: android, backup, bash, bash-script, ftp, ftp-client, obsidian-md, script, termux, windows
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Obsync: A Two-Way Obsidian Sync
Easily sync your Obsidian vault between your desktop and mobile device without purchasing Obsidian Sync. This script leverages FTP for file transfer and ensures data integrity with backup capabilities.
### Key Features:
1. Two-Way Sync: Sync files and folders between desktop and mobile to keep your vault updated on both devices.
2. Exclusion Rules: Customize which files and folders to exclude from the sync to avoid unnecessary data transfer.
3. Automated Backup: Create local backups on your Android device before syncing to prevent data loss.
---
## Before Reading:
> [!Important]
> This guide focuses on **Windows** and **Android**, but the steps can be adapted for other operating systems as well.> [!Caution]
> Test this script with a mock vault first to ensure the safety of your data. This precaution helps prevent any accidental loss or corruption of your actual vault. Once you have confirmed that everything works as intended, you can proceed to use your main vault.> [!TIP]
> Got a suggestion? Comment below!
---
## Requirements
- **FTP Server running on Desktop** [How to set up an FTP server on Windows?](https://www.windowscentral.com/how-set-and-manage-ftp-server-windows-10)
> Ensure the Obsidian folder on your desktop is accessible through FTP from your mobile beforehand.
- **A Terminal in Mobile** (preferably [Termux](https://github.com/KitsunedFox/termux-monet))## Installation
1. **Install Required Packages in Termux:**
```sh
pkg update && pkg install lftp rsync
```
2. **Create the Sync Script:**
```sh
nano obsidian-sync.sh
```
3. **Add the following code to the script:**
> Don't forget to change the configurations in the `FTP server details` and `Patterns to exclude`.
```sh
#!/bin/bash# FTP server details
FTP_HOST="ftp://192.168.1.100:21" # e.g., 192.168.1.100:21
FTP_USER="user"
FTP_PASS="password"
REMOTE_DIR="/Documents/Obsidian" # Obsidian location on Desktop
LOCAL_DIR="/storage/1BC4-1763/Documents/Obsidian" # Obsidian location on Mobile
BACKUP_DIR="/storage/1BC4-1763/Documents/Obsidian-Backup" # Backup location on Mobile# Patterns to exclude
EXCLUDE_PATTERNS=(
# "*.tmp" # Exclude all .tmp files
# "*.bak" # Exclude all .bak files
# "cache/" # Exclude cache directory
# "logs/" # Exclude logs directory
# "DoNotSync.md" # Exclude specific file
".obsidian/" # Exclude Obsidian configs
)# Convert EXCLUDE_PATTERNS to rsync format
RSYNC_EXCLUDES=()
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
RSYNC_EXCLUDES+=(--exclude "$pattern")
done# Convert EXCLUDE_PATTERNS to lftp format
LFTP_EXCLUDES=""
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
LFTP_EXCLUDES+="--exclude $pattern "
done# Function to create a backup using rsync
backup_files() {
rsync -av --delete "${RSYNC_EXCLUDES[@]}" "$LOCAL_DIR/" "$BACKUP_DIR/"
}# Sync function using lftp
sync_files() {
lftp -u "$FTP_USER","$FTP_PASS" "$FTP_HOST" < Make sure to keep Termux running in background.### Method 2: Using Automate/Tasker with Termux:Tasker Plugin
For a more flexible approach, you can use automation apps like Automate or Tasker along with the Termux:Tasker plugin to run the script based on specific events or conditions.
#### Using Automate:
1. **Install Automate and Termux**:
Download and install [Automate](https://play.google.com/store/apps/details?id=com.llamalab.automate) from the Play Store and the [Termux:Tasker](https://github.com/KitsunedFox/termux-tasker?tab=readme-ov-file#plugin-configuration) plugin from the Play Store.2. **Create a New Flow in Automate**:
Open Automate and create a new flow.3. **Add a Plug-in action Block**:
- Add a "Plug-in action" block to the flow.
- In the "Pick plug-in" field, select Termux.
- This will open a new window.
- In executable field, place your `/path/to/obsidian-sync.sh`.
- You can put your `obsidian-sync.sh` in `/.termux/tasker` to avoid any issue.
- Save and exit, both tasker plugin and the flow.4. **Add a Trigger Block**:
Add a trigger block (like "Time" for scheduled sync or "Wi-Fi Connected" for event-based sync) and connect it to Plug-in action block.
> I'll create a flow for this later, I'm tired now.
5. **Save and Enable the Flow**:
Save your flow and enable it. The script will now run automatically based on your defined trigger.#### Using Tasker:
1. **Install Tasker and Termux:Tasker Plugin**:
Download and install [Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm) and the [Termux:Tasker](https://github.com/KitsunedFox/termux-tasker?tab=readme-ov-file#plugin-configuration) plugin from the Play Store.2. **Create a New Profile in Tasker**:
Open Tasker and create a new profile.3. **Set a Trigger**:
- Choose a trigger (like "Time" for scheduled sync or "Wi-Fi Connected" for event-based sync).4. **Add a Task**:
- Create a new task and add an action.
- Select "Plugin" -> "Termux:Tasker".
- Tap the configuration icon and enter the path to your script:
```sh
/data/data/com.termux/files/home/obsidian-sync.sh
```
- You can put your `obsidian-sync.sh` in `/.termux/tasker` to avoid any issue.5. **Save and Enable the Profile**:
Save your profile and enable it. The script will now run automatically based on the defined trigger.By setting up automation, you ensure that your Obsidian vault syncs regularly without manual intervention. Choose the method that best fits your needs and enjoy seamless synchronization across your devices.
Hope this helps!
---
## What's Next?
- Add some picture for better understanding.
- A Video Guide.
- A Automate flow for Obsync.---
Also don't hesitate to comment below for potential improvements or any flaws in the code. Or improve the gist formatting anyway.
Thank you 💖