【问题标题】:i want to created a folder with current date and copy files local ec2 instance to newly created folder , i want to automated this for every day我想创建一个具有当前日期的文件夹并将文件本地 ec2 实例复制到新创建的文件夹,我想每天自动执行此操作
【发布时间】:2019-05-21 21:42:27
【问题描述】:

我正在尝试自动化备份过程,因此在 /var/opt/.../backup-daily 文件夹中的当前 ec2 Linux 实例中,它们将是 jar 文件,因此我希望将它们复制到新创建的带有当前时间戳的文件夹,然后压缩文件,并将压缩文件复制到 s3 存储桶中,稍后我想删除该文件夹,它是 90 天的,请提供一个 Linux 脚本

我正在手动更新这个过程,但是我需要一个每天早上10:00运行的脚本。我的老板让我写一个脚本来自动化它

retentionDate=(datetime.now() - timedelta(days=90)).date()
sourceDirectory="give the directory where folder will be created with dateandtime"

我无法自动化这个过程,我只需要创建一个带有时间戳的新文件夹并将所有 jar 文件从备份文件夹复制到时间戳文件夹,然后,该文件夹应该是压缩文件然后上传到 s3 存储桶中,并在 90 天后删除文件

【问题讨论】:

标签: bash amazon-web-services amazon-s3 backup unix-timestamp


【解决方案1】:

试试这个脚本,做一些改动:

#!/bin/bash
origin_dir="/var/opt/backup"
dest_dir=$(date +"/data/bkp_%F" -u)
log=$(date +"/data/bkp_%F.log" -u)

#send every output to log file
exec >> $log 2>&1

#copy the files do newer timestamped dir
cp -v $origin_dir/*.jar $dest_dir/

#zip files
bzip2 -v --compress --best $dest_dir/*.jar

#delete older dir with more than 90 days
find /data/ -type d -name 'bkp_*' -mtime +90 -exec rm -r -v {} \;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 2022-10-15
    • 2019-05-30
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多