mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 07:22: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:
@ -45,11 +45,14 @@ public function download(string $src, string $dest): void
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO Implement delete method
|
||||
*/
|
||||
public function delete(string $path): void
|
||||
public function delete(string $src): void
|
||||
{
|
||||
//
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('dropbox/delete-file.sh', [
|
||||
'src' => $src,
|
||||
'token' => $this->storageProvider->credentials['token'],
|
||||
]),
|
||||
'delete-from-dropbox'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public function upload(string $src, string $dest): array
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('ftp/upload.sh', [
|
||||
'src' => $src,
|
||||
'dest' => $this->storageProvider->credentials['path'].'/'.$dest,
|
||||
'dest' => $dest,
|
||||
'host' => $this->storageProvider->credentials['host'],
|
||||
'port' => $this->storageProvider->credentials['port'],
|
||||
'username' => $this->storageProvider->credentials['username'],
|
||||
@ -33,7 +33,7 @@ public function download(string $src, string $dest): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('ftp/download.sh', [
|
||||
'src' => $this->storageProvider->credentials['path'].'/'.$src,
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
'host' => $this->storageProvider->credentials['host'],
|
||||
'port' => $this->storageProvider->credentials['port'],
|
||||
@ -46,11 +46,19 @@ public function download(string $src, string $dest): void
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO Implement delete method
|
||||
*/
|
||||
public function delete(string $path): void
|
||||
public function delete(string $src): void
|
||||
{
|
||||
//
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('ftp/delete-file.sh', [
|
||||
'src' => $src,
|
||||
'host' => $this->storageProvider->credentials['host'],
|
||||
'port' => $this->storageProvider->credentials['port'],
|
||||
'username' => $this->storageProvider->credentials['username'],
|
||||
'password' => $this->storageProvider->credentials['password'],
|
||||
'ssl' => $this->storageProvider->credentials['ssl'],
|
||||
'passive' => $this->storageProvider->credentials['passive'],
|
||||
]),
|
||||
'delete-from-ftp'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,12 @@ class Local extends AbstractStorage
|
||||
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$destDir = dirname($this->storageProvider->credentials['path'].$dest);
|
||||
$destFile = basename($this->storageProvider->credentials['path'].$dest);
|
||||
$destDir = dirname($dest);
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('local/upload.sh', [
|
||||
'src' => $src,
|
||||
'dest_dir' => $destDir,
|
||||
'dest_file' => $destFile,
|
||||
'dest_file' => $dest,
|
||||
]),
|
||||
'upload-to-local'
|
||||
);
|
||||
@ -30,20 +29,15 @@ public function download(string $src, string $dest): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('local/download.sh', [
|
||||
'src' => $this->storageProvider->credentials['path'].$src,
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
]),
|
||||
'download-from-local'
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(string $path): void
|
||||
public function delete(string $src): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('local/delete.sh', [
|
||||
'path' => $this->storageProvider->credentials['path'].$path,
|
||||
]),
|
||||
'delete-from-local'
|
||||
);
|
||||
$this->server->os()->deleteFile($src);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public function upload(string $src, string $dest): array
|
||||
$uploadCommand = $this->getScript('s3/upload.sh', [
|
||||
'src' => $src,
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'dest' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$dest),
|
||||
'dest' => $this->prepareS3Path($dest),
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
'region' => $this->storageProvider->credentials['region'],
|
||||
@ -52,7 +52,7 @@ public function download(string $src, string $dest): void
|
||||
$provider = $this->storageProvider->provider();
|
||||
|
||||
$downloadCommand = $this->getScript('s3/download.sh', [
|
||||
'src' => $this->prepareS3Path($this->storageProvider->credentials['path'].'/'.$src),
|
||||
'src' => $this->prepareS3Path($src),
|
||||
'dest' => $dest,
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
@ -71,8 +71,21 @@ public function download(string $src, string $dest): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO Implement delete method
|
||||
*/
|
||||
public function delete(string $path): void {}
|
||||
public function delete(string $src): void
|
||||
{
|
||||
/** @var \App\StorageProviders\S3 $provider */
|
||||
$provider = $this->storageProvider->provider();
|
||||
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('s3/delete-file.sh', [
|
||||
'src' => $this->prepareS3Path($src),
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
'region' => $this->storageProvider->credentials['region'],
|
||||
'endpoint' => $provider->getApiUrl(),
|
||||
]),
|
||||
'delete-from-s3'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ public function upload(string $src, string $dest): array;
|
||||
|
||||
public function download(string $src, string $dest): void;
|
||||
|
||||
public function delete(string $path): void;
|
||||
public function delete(string $src): void;
|
||||
}
|
||||
|
6
app/SSH/Storage/scripts/dropbox/delete-file.sh
Normal file
6
app/SSH/Storage/scripts/dropbox/delete-file.sh
Normal file
@ -0,0 +1,6 @@
|
||||
curl --location --request POST 'https://api.dropboxapi.com/2/files/delete_v2' \
|
||||
--header 'Authorization: Bearer __token__' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
"path": "__src__"
|
||||
}'
|
1
app/SSH/Storage/scripts/ftp/delete-file.sh
Normal file
1
app/SSH/Storage/scripts/ftp/delete-file.sh
Normal file
@ -0,0 +1 @@
|
||||
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -Q "DELE /__src__"
|
@ -1 +0,0 @@
|
||||
rm __path__
|
@ -1,2 +1,2 @@
|
||||
mkdir -p __dest_dir__
|
||||
cp __src__ __dest_dir__/__dest_file__
|
||||
cp __src__ __dest_file__
|
||||
|
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