

@Bean
public Job helloWorldJob() {
return jobBuilderFactory.get("helloWorldJob")
.incrementer(new RunIdIncrementer()) // 매번 다른 ID로 실행 가능하게 설정
.start(helloWorldStep1()) // 첫 번째 스텝 시작
.build();
}
Job -> 하나 이상의 step으로 구성된 단위 작업
RunIdIncrementer -> 실행 시마다 새로운 JobInstance ID를 부여해 여러 번 동일한 작업을 실행할 수 있도록 / 같은 Job을 여러 번 실행할 때 충돌을 방지
@Bean
public Step helloWorldStep1() {
return stepBuilderFactory.get("helloWorldStep1")
.tasklet(helloWorldTasklet()) // Tasklet 설정
.build();
}
Step -> Job의 하위 단위로, 배치 작업의 한 단계를 의미
Tasklet을 사용하여 간단한 작업을 수행
@Bean
public Tasklet helloWorldTasklet() {
return (stepContribution, chunkContext) -> {
System.out.println("helloWorld!"); // "helloWorld!" 메시지 출력
return RepeatStatus.FINISHED; // 작업 완료 표시
};
}
tasklet -> 단순한 반복 가능한 작업 단위
RepeatStatus.FINISHED를 반환하여 작업이 한번만 실행되고 종료됨
Spring Batch는 하나의 큰 작업(Job)을 여러 단계(Step)로 나누어 처리, 각 Step 안에서는 특정 작업을 실행하는 코드가 Tasklet이나 Chunk로 구현
mysqldump -u root SpringBatch_10 > SpringBatch_10.sql
-u root 데이터베이스에 접근할 사용자를 지정SpringBatch_10 백업할 데이터베이스 이름 > SpringBatch_10.sql 백업 결과를 SpringBatch_10.sql 파일로 저장 mysql -u root SpringBatch_10_backup < SpringBatch_10.sql
-u root MySQL 서버에 접근할 사용자SpringBatch_10_backup 복원할 데이터베이스 이름< SpringBatch_10.sql 백업 파일로부터 데이터를 가져와 복원동일한 데이터베이스 이름으로 복원할 경우, 기존 데이터가 덮어쓰기될 수 있다.