Last active
December 11, 2021 09:04
-
-
Save cecepm/78417c4328715d852149e474628cf032 to your computer and use it in GitHub Desktop.
Bash Untuk Pemula - Membuat Backup Script
This file contains 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 | |
# | |
# - 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 |
This file contains 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 | |
# | |
# 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 |
This file contains 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 | |
# | |
# - 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 |
This file contains 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 "Hello World!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment