mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 23:42:34 +00:00
Edit & Download (local) Backups (#436)
* Allow editing of backups * pint updates * setup of backup download * allow download for local backup files * delete uploaded files on delete of BackupFile * pint updates * S3 upload & download fixes * Deletion of backup files * support $ARCH selector for s3 installation * delete files when deleting backup * fixed ui issue * adjustment * Use system temp path for downloads --------- Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
30
app/SSH/Storage/scripts/s3/delete-file.sh
Normal file
30
app/SSH/Storage/scripts/s3/delete-file.sh
Normal file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
install_aws_cli() {
|
||||
echo "Installing AWS CLI"
|
||||
ARCH=$(uname -m)
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-$ARCH.zip" -o "aws.zip"
|
||||
unzip -q aws.zip
|
||||
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
|
||||
rm -rf aws.zip aws
|
||||
}
|
||||
|
||||
if ! command_exists aws; then
|
||||
install_aws_cli
|
||||
fi
|
||||
|
||||
if ! command_exists aws; then
|
||||
echo "Error: AWS CLI installation failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export AWS_ACCESS_KEY_ID=__key__
|
||||
export AWS_SECRET_ACCESS_KEY=__secret__
|
||||
export AWS_DEFAULT_REGION=__region__
|
||||
export AWS_ENDPOINT_URL=__endpoint__
|
||||
|
||||
aws s3 rm s3://__bucket__/__src__
|
@ -1,32 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configure AWS CLI with provided credentials
|
||||
/usr/local/bin/aws configure set aws_access_key_id "__key__"
|
||||
/usr/local/bin/aws configure set aws_secret_access_key "__secret__"
|
||||
/usr/local/bin/aws configure set default.region "__region__"
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Use the provided endpoint in the correct format
|
||||
ENDPOINT="__endpoint__"
|
||||
BUCKET="__bucket__"
|
||||
REGION="__region__"
|
||||
install_aws_cli() {
|
||||
echo "Installing AWS CLI"
|
||||
ARCH=$(uname -m)
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-$ARCH.zip" -o "aws.zip"
|
||||
unzip -q aws.zip
|
||||
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
|
||||
rm -rf aws.zip aws
|
||||
}
|
||||
|
||||
# Ensure that DEST does not have a trailing slash
|
||||
SRC="__src__"
|
||||
DEST="__dest__"
|
||||
if ! command_exists aws; then
|
||||
install_aws_cli
|
||||
fi
|
||||
|
||||
# Download the file from S3
|
||||
echo "Downloading s3://__bucket__/__src__ to __dest__"
|
||||
download_output=$(/usr/local/bin/aws s3 cp "s3://$BUCKET/$SRC" "$DEST" --endpoint-url="$ENDPOINT" --region "$REGION" 2>&1)
|
||||
download_exit_code=$?
|
||||
|
||||
# Log output and exit code
|
||||
echo "Download command output: $download_output"
|
||||
echo "Download command exit code: $download_exit_code"
|
||||
|
||||
# Check if the download was successful
|
||||
if [ $download_exit_code -eq 0 ]; then
|
||||
echo "Download successful"
|
||||
else
|
||||
echo "Download failed"
|
||||
if ! command_exists aws; then
|
||||
echo "Error: AWS CLI installation failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export AWS_ACCESS_KEY_ID=__key__
|
||||
export AWS_SECRET_ACCESS_KEY=__secret__
|
||||
export AWS_DEFAULT_REGION=__region__
|
||||
export AWS_ENDPOINT_URL=__endpoint__
|
||||
|
||||
if aws s3 cp s3://__bucket__/__src__ __dest__; then
|
||||
echo "Download successful"
|
||||
fi
|
||||
|
@ -1,59 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if AWS CLI is installed
|
||||
if ! command -v aws &> /dev/null
|
||||
then
|
||||
echo "AWS CLI is not installed. Installing..."
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Detect system architecture
|
||||
install_aws_cli() {
|
||||
echo "Installing AWS CLI"
|
||||
ARCH=$(uname -m)
|
||||
if [ "$ARCH" == "x86_64" ]; then
|
||||
CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
|
||||
elif [ "$ARCH" == "aarch64" ]; then
|
||||
CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip"
|
||||
else
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
fi
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-$ARCH.zip" -o "aws.zip"
|
||||
unzip -q aws.zip
|
||||
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
|
||||
rm -rf aws.zip aws
|
||||
}
|
||||
|
||||
# Download and install AWS CLI
|
||||
sudo curl "$CLI_URL" -o "awscliv2.zip"
|
||||
sudo unzip awscliv2.zip
|
||||
sudo ./aws/install --update
|
||||
sudo rm -rf awscliv2.zip aws
|
||||
|
||||
echo "AWS CLI installation completed."
|
||||
else
|
||||
echo "AWS CLI is already installed."
|
||||
/usr/local/bin/aws --version
|
||||
if ! command_exists aws; then
|
||||
install_aws_cli
|
||||
fi
|
||||
|
||||
# Configure AWS CLI with provided credentials
|
||||
/usr/local/bin/aws configure set aws_access_key_id "__key__"
|
||||
/usr/local/bin/aws configure set aws_secret_access_key "__secret__"
|
||||
|
||||
# Use the provided endpoint in the correct format
|
||||
ENDPOINT="__endpoint__"
|
||||
BUCKET="__bucket__"
|
||||
REGION="__region__"
|
||||
|
||||
# Ensure that DEST does not have a trailing slash
|
||||
SRC="__src__"
|
||||
DEST="__dest__"
|
||||
|
||||
# Upload the file
|
||||
echo "Uploading __src__ to s3://$BUCKET/$DEST"
|
||||
upload_output=$(/usr/local/bin/aws s3 cp "$SRC" "s3://$BUCKET/$DEST" --endpoint-url="$ENDPOINT" --region "$REGION" 2>&1)
|
||||
upload_exit_code=$?
|
||||
|
||||
# Log output and exit code
|
||||
echo "Upload command output: $upload_output"
|
||||
echo "Upload command exit code: $upload_exit_code"
|
||||
|
||||
# Check if the upload was successful
|
||||
if [ $upload_exit_code -eq 0 ]; then
|
||||
echo "Upload successful"
|
||||
else
|
||||
echo "Upload failed"
|
||||
if ! command_exists aws; then
|
||||
echo "Error: AWS CLI installation failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export AWS_ACCESS_KEY_ID=__key__
|
||||
export AWS_SECRET_ACCESS_KEY=__secret__
|
||||
export AWS_DEFAULT_REGION=__region__
|
||||
export AWS_ENDPOINT_URL=__endpoint__
|
||||
|
||||
if aws s3 cp __src__ s3://__bucket__/__dest__; then
|
||||
echo "Upload successful"
|
||||
fi
|
||||
|
Reference in New Issue
Block a user