Yesterday, 05:47 AM
Fast way to move users across 2 servers. use the API. Here is a bash script.
#!/bin/bash
# Set these variables:
SRC_URL="http://SOURCE_JELLYFIN:8096"
SRC_KEY="SOURCE_ADMIN_API_KEY"
DEST_URL="http://DEST_JELLYFIN:8096"
DEST_KEY="DEST_ADMIN_API_KEY"
# Get all users from source
users_json=$(curl -s -H "X-Emby-Token: $SRC_KEY" "$SRC_URL/Users")
# Parse usernames, skip administrator
usernames=$(echo "$users_json" | jq -r '.[] | select(.Name!="Administrator") | .Name')
echo "Cloning users:"
for name in $usernames; do
# Check if user already exists on dest
exists=$(curl -s -H "X-Emby-Token: $DEST_KEY" "$DEST_URL/Users" | jq -r ".[] | select(.Name==\"$name\") | .Name")
if [[ "$exists" == "$name" ]]; then
echo " - $name already exists on destination, skipping."
continue
fi
# Create user on destination
create_resp=$(curl -s -X POST "$DEST_URL/Users/New" \
-H "X-Emby-Token: $DEST_KEY" \
-H "Content-Type: application/json" \
--data "{\"Name\":\"$name\"}")
# Get new user ID
user_id=$(echo "$create_resp" | jq -r .Id)
if [[ "$user_id" == "null" || -z "$user_id" ]]; then
echo " - Failed to create $name."
continue
fi
# Set password to the username
curl -s -X POST "$DEST_URL/Users/$user_id/Password" \
-H "X-Emby-Token: $DEST_KEY" \
-H "Content-Type: application/json" \
--data "{\"NewPw\":\"$name\"}" >/dev/null
echo " - $name cloned. Password: $name"
done
echo "Done."
#!/bin/bash
# Set these variables:
SRC_URL="http://SOURCE_JELLYFIN:8096"
SRC_KEY="SOURCE_ADMIN_API_KEY"
DEST_URL="http://DEST_JELLYFIN:8096"
DEST_KEY="DEST_ADMIN_API_KEY"
# Get all users from source
users_json=$(curl -s -H "X-Emby-Token: $SRC_KEY" "$SRC_URL/Users")
# Parse usernames, skip administrator
usernames=$(echo "$users_json" | jq -r '.[] | select(.Name!="Administrator") | .Name')
echo "Cloning users:"
for name in $usernames; do
# Check if user already exists on dest
exists=$(curl -s -H "X-Emby-Token: $DEST_KEY" "$DEST_URL/Users" | jq -r ".[] | select(.Name==\"$name\") | .Name")
if [[ "$exists" == "$name" ]]; then
echo " - $name already exists on destination, skipping."
continue
fi
# Create user on destination
create_resp=$(curl -s -X POST "$DEST_URL/Users/New" \
-H "X-Emby-Token: $DEST_KEY" \
-H "Content-Type: application/json" \
--data "{\"Name\":\"$name\"}")
# Get new user ID
user_id=$(echo "$create_resp" | jq -r .Id)
if [[ "$user_id" == "null" || -z "$user_id" ]]; then
echo " - Failed to create $name."
continue
fi
# Set password to the username
curl -s -X POST "$DEST_URL/Users/$user_id/Password" \
-H "X-Emby-Token: $DEST_KEY" \
-H "Content-Type: application/json" \
--data "{\"NewPw\":\"$name\"}" >/dev/null
echo " - $name cloned. Password: $name"
done
echo "Done."