Last active
          October 3, 2018 21:25 
        
      - 
      
- 
        Save davidalves1/c43fbaae217c81dacf95b6ab95896dbb to your computer and use it in GitHub Desktop. 
    Backup the database in Linux by compressing the generated file
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | # Current datetime | |
| now="$(date +'%Y%m%d-%H%M')" | |
| # DB credentials | |
| db_name=my_db_name | |
| db_host=my_db_hostname | |
| db_user=my_db_user | |
| db_password=my_db_password | |
| ### EXAMPLE ### | |
| #db_name=db_teste | |
| #db_host=localhost | |
| #db_user=user | |
| #db_password=123456 | |
| # Backup file | |
| sql_file='db_backup_'$now'.sql' | |
| echo 'Backing up the database on the backup folder' | |
| mysqldump -h $db_host -u $db_user -p$db_password -v $db_name | gzip > './backup/'$sql_file'.gz' | |
| # Para voltar o backup | |
| # gunzip < dump.sql.gz | mysql -u USUARIO -pPASSWORD -v | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment