Skip to content

Instantly share code, notes, and snippets.

@cecepm
Last active December 11, 2021 09:04
Show Gist options
  • Save cecepm/78417c4328715d852149e474628cf032 to your computer and use it in GitHub Desktop.
Save cecepm/78417c4328715d852149e474628cf032 to your computer and use it in GitHub Desktop.
Bash Untuk Pemula - Membuat Backup Script
#!/bin/bash
#
# - print date time using command `date`
# date +%F
#
# - create tar.gz archive
# tar czf archive.tar.gz folder
SOURCE_DIR=/usr/local/html
BACKUP_DIR=/data/backup
FILENAME="apps-$(date +%F).tar.gz"
cd ${SOURCE_DIR}
tar czf ${BACKUP_DIR}/${FILENAME} apps
#!/bin/bash
#
# find files modified in the last 7 days and delete them:
# find root_path -daystart -mtime -7 -delete
DAYS=${1:-7}
BACKUP_DIR=/data/backup
# delete file older than x days
find ${BACKUP_DIR} -type f -mtime +${DAYS} -delete
#!/bin/bash
#
# - create file
# touch filename.tar.gz
#
# - create file, and change last modified time to specific date
# touch -d 2021-12-10 filename.tar.gz
#
# - print date time using command `date`
# date +%F
#
# - print date time, relative to now
# date +%F --date="1 days ago"
BACKUP_DIR=/data/backup
for x in {1..7}; do
touch -d $(date +%F --date="${x} days ago") ${BACKUP_DIR}/apps-$(date +%F --date="${x} days ago").tar.gz
done
#!/bin/bash
echo "Hello World!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment