Last active
June 12, 2024 07:33
-
-
Save zycon/a9d857865597ec41c93d0f14ff912528 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
echo "folder path, . folder current directory" | |
read SOURCE_FOLDER | |
echo "userid" | |
read CRED | |
echo "hostname" | |
read HOST | |
ZIP_FILE="/tmp/backup.zip" | |
NEXTCLOUD_URL="https://"$HOST"/remote.php/dav/files/"$CRED"/docker-try/" | |
NEXTCLOUD_USER=$CRED | |
NEXTCLOUD_PASSWORD=$CRED | |
# Function to print usage | |
echo $NEXTCLOUD_URL | |
usage() { | |
echo "Usage: $0 <source-folder>" | |
exit 1 | |
} | |
# Check if source folder is provided | |
if [ -z "$SOURCE_FOLDER" ]; then | |
usage | |
fi | |
# Check if source folder exists | |
if [ ! -d "$SOURCE_FOLDER" ]; then | |
echo "Error: Source folder '$SOURCE_FOLDER' does not exist." | |
exit 1 | |
fi | |
# Create a zip of the folder | |
echo "Zipping the folder '$SOURCE_FOLDER'..." | |
zip -r "$ZIP_FILE" "$SOURCE_FOLDER" | |
if [ $? -ne 0 ]; then | |
echo "Error: Failed to create zip." | |
exit 1 | |
fi | |
# Upload the zip file to Nextcloud | |
echo "Uploading the zip file to Nextcloud..." | |
curl -u "$NEXTCLOUD_USER:$NEXTCLOUD_PASSWORD" -T "$ZIP_FILE" "$NEXTCLOUD_URL" | |
if [ $? -ne 0 ]; then | |
echo "Error:" | |
exit 1 | |
fi | |
# Clean up | |
echo "Cleaning up..." | |
rm "$ZIP_FILE" | |
history -c | |
history -w | |
echo "completed." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment